Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f266380
First version of Nim Client
hokamoto Sep 1, 2019
18d367a
Add some codes
hokamoto Sep 5, 2019
9639569
Add some codes
hokamoto Sep 5, 2019
a999b5e
Add some codes
hokamoto Sep 8, 2019
5d73b11
Add some codes
hokamoto Sep 8, 2019
3880039
Add some codes
hokamoto Sep 12, 2019
c48f0a0
First version of Nim Client
hokamoto Sep 1, 2019
c5e4713
Add some codes
hokamoto Sep 5, 2019
feb96b1
Add some codes
hokamoto Sep 5, 2019
5fdc0ab
Add some codes
hokamoto Sep 8, 2019
ae33303
Add some codes
hokamoto Sep 8, 2019
ba35508
Add some codes
hokamoto Sep 12, 2019
fc74ece
[Dart] Fix README template and update testing doco (#3809)
nickmeinhold Sep 3, 2019
7b4a201
Support custom git repository (#3757)
qmuntal Sep 3, 2019
2451702
Add links to article and video (#3820)
wing328 Sep 3, 2019
9ef73eb
Better Go code format (#3819)
wing328 Sep 4, 2019
c90c6c8
Add gRPC Protobuf schema generator (#3818)
wing328 Sep 4, 2019
bdfed92
1792 fix remote spec handling and hash calculation (#3440)
Sep 4, 2019
7c5cfb7
fixed bug where nullApi.java would be generated. Instead, generated …
bensimpson-ch Sep 4, 2019
99eb680
Revert "1792 fix remote spec handling and hash calculation (#3440)"
wing328 Sep 4, 2019
ac1f19d
Add nickmeinhold to Dart technical committee (#3830)
wing328 Sep 4, 2019
9cbcebc
Bug #2845 typescript angular inheritance (#3812)
mnahkies Sep 5, 2019
9ba0dd0
fix warnings in csharp-netcore client (#3831)
wing328 Sep 5, 2019
5d21a8f
Add missing files to the form request (#3834)
etherealjoy Sep 5, 2019
8c637fb
[client][go] avoid duplicated reflect imports (#3847)
qmuntal Sep 6, 2019
f26f726
Following up for #3440 (1792 fix remote spec handling and hash calcul…
fuj1g0n Sep 6, 2019
4a1eb91
Add a link (#3850)
ackintosh Sep 7, 2019
3228ca2
Add Element AI to the list (#3856)
wing328 Sep 7, 2019
2fb08fb
maven-plugin-plugin 3.6.0 (#3854)
sullis Sep 7, 2019
221443a
[Java][okhttp-gson] fix failure to deserialize floats (#3846)
bensimpson-ch Sep 7, 2019
adf1297
Adds Http Info To Dart Api (#3851)
austbot Sep 7, 2019
86adb0a
[C++][Pistache] Add missing setter for arrays (#3837)
muttleyxd Sep 7, 2019
82f00f2
typescript-inversify: improve check for required parameters, support …
bodograumann Sep 9, 2019
0f10987
[typescript-angular] allow empty string basePath (#3489)
martinnovak Sep 9, 2019
bf441c2
Fix/r/serialization fix and minor 3xx resp fix (#3817)
Ramanth Sep 10, 2019
e51ffbe
typescript-axios: Fix baseoptions (#3866)
7474 Sep 10, 2019
0396bb4
Rename gRPC generator to "protobuf-schema" (#3864)
wing328 Sep 10, 2019
3dd0ebd
Prepare v4.1.2 release (#3873)
wing328 Sep 11, 2019
58ec946
fix version in readme
macjohnny Sep 11, 2019
580ca11
BugFix #2053 Spring Boot fails to parse LocalDate query parameter (#3…
peyerroger Sep 11, 2019
fbb3b27
update doc, samples (#3875)
wing328 Sep 11, 2019
549fc8f
update stable release
wing328 Sep 11, 2019
bface47
Update the batch for Windows
hokamoto Sep 12, 2019
5a28be0
Merge branch 'nim-client' of github.com:hokamoto/openapi-generator in…
hokamoto Sep 12, 2019
19cc13b
Merge remote-tracking branch 'upstream/master' into nim-client
hokamoto Sep 12, 2019
2db44c7
Add a test snippet
hokamoto Sep 12, 2019
bcec49b
Update ensure-up-to-date
hokamoto Sep 12, 2019
7276034
Add Nim to README.md
hokamoto Sep 12, 2019
090875b
Ran ensure-up-to-date to pass CircleCI tests
hokamoto Sep 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add some codes
  • Loading branch information
hokamoto committed Sep 12, 2019
commit ba355082a4d9c47ebf2ba3f72e244ff22599a256
4 changes: 1 addition & 3 deletions bin/nim-client-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
#ags="$@ generate -t modules/openapi-generator/src/main/resources/nim-client -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml --additional-properties packageName=petstore -g nim -o samples/client/petstore/nim"
#ags="$@ generate -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml --additional-properties packageName=petstore -g nim -o samples/client/petstore/nim"
ags="$@ generate -DdebugSwagger -DdebugOperations -DdebugModels -t modules/openapi-generator/src/main/resources/nim-client -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml --additional-properties packageName=petstore -g nim -o samples/client/petstore/nim"
ags="$@ generate -t modules/openapi-generator/src/main/resources/nim-client -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml --additional-properties packageName=petstore -g nim -o samples/client/petstore/nim"

java ${JAVA_OPTS} -jar ${executable} ${ags}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public void processOpts() {

apiPackage = File.separator + packageName + File.separator + "apis";
modelPackage = File.separator + packageName + File.separator + "models";
supportingFiles.add(new SupportingFile("lib.mustache", "", packageName + ".nim"));
}

@Override
Expand Down Expand Up @@ -245,7 +246,29 @@ public String getTypeDeclaration(Schema p) {
return typeMapping.get(schemaType);
}

return schemaType;
if (schemaType.matches("\\d.*")) { // starts with number
return "`" + schemaType + "`";
} else {
return schemaType;
}
}

@Override
public String toVarName(String name) {
if (isReservedWord(name)) {
name = escapeReservedWord(name);
}

if (name.matches("^\\d.*")) {
name = "`" + name + "`";
}

return name;
}

@Override
public String toParamName(String name) {
return toVarName(name);
}

@Override
Expand All @@ -263,11 +286,24 @@ protected boolean needToImport(String type) {

@Override
public String toEnumName(CodegenProperty property) {
return StringUtils.camelize(property.name, false);
String name = StringUtils.camelize(property.name, false);

if (name.matches("\\d.*")) { // starts with number
return "`" + name + "`";
} else {
return name;
}
}

@Override
public String toEnumVarName(String name, String datatype) {
return StringUtils.camelize(name, false);
name = name.replace(" ", "_");
name = StringUtils.camelize(name, false);

if (name.matches("\\d.*")) { // starts with number
return "`" + name + "`";
} else {
return name;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're using 4 space indention so I'll reformat the code in a separate PR.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This API client was generated by the [OpenAPI Generator](https://openapi-generat
Put the package under your project folder and add the following to the nimble file of your project:

```
requires "{{{packageName}}}"
import {{{packageName}}}
```

## Documentation for API Endpoints
Expand All @@ -38,6 +38,6 @@ Module | Proc | HTTP request | Description
To generate documentation with Nim DocGen, use:

```
nim doc --project --index:on src/api_client.nim
nim doc --project --index:on {{{packageName}}}.nim
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{>header}}
# Models
{{#models}}{{#model}}import {{packageName}}/models/{{classFilename}}
{{/model}}{{/models}}{{#models}}
{{#model}}export {{classFilename}}{{/model}}{{/models}}

# APIs
{{#apiInfo}}{{#apis}}import {{packageName}}/apis/{{classFilename}}
{{/apis}}{{/apiInfo}}{{#apiInfo}}
{{#apis}}export {{classFilename}}
{{/apis}}{{/apiInfo}}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ import tables

{{#imports}}import {{import}}
{{/imports}}{{#models}}{{#model}}{{#vars}}{{#isEnum}}
type {{enumName}}* {.pure.} = enum{{#allowableValues}}{{#enumVars}}
type {{{enumName}}}* {.pure.} = enum{{#allowableValues}}{{#enumVars}}
{{{name}}}{{/enumVars}}{{/allowableValues}}
{{/isEnum}}{{/vars}}
type {{{classname}}}* = object
## {{{description}}}{{#vars}}
{{{name}}}*: {{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#description}} ## {{{description}}}{{/description}}{{/vars}}
{{#vars}}{{#isEnum}}
func `%`*(v: {{enumName}}): JsonNode =
func `%`*(v: {{{enumName}}}): JsonNode =
let str = case v:{{#allowableValues}}{{#enumVars}}
of {{{name}}}: {{{value}}}{{/enumVars}}{{/allowableValues}}
of {{{enumName}}}.{{{name}}}: {{{value}}}{{/enumVars}}{{/allowableValues}}

JsonNode(kind: JString, str: str)

func `$`*(v: {{enumName}}): string =
func `$`*(v: {{{enumName}}}): string =
result = case v:{{#allowableValues}}{{#enumVars}}
of {{{name}}}: {{{value}}}{{/enumVars}}{{/allowableValues}}
of {{{enumName}}}.{{{name}}}: {{{value}}}{{/enumVars}}{{/allowableValues}}
{{/isEnum}}{{/vars}}{{/model}}{{/models}}
Original file line number Diff line number Diff line change
Expand Up @@ -3,163 +3,12 @@ import httpclient
import logging
import options

import {{{packageName}}}

import config

# Models
{{#models}}{{#model}}import {{packageName}}/models/{{classFilename}}
{{/model}}{{/models}}
# APIs
{{#apiInfo}}{{#apis}}import {{packageName}}/apis/{{classFilename}}
{{/apis}}{{/apiInfo}}
let logger = newConsoleLogger()
addHandler(logger)

let client = newHttpClient()
client.headers["User-Agent"] = config.useragent

# Test Pet
let category = Category(id: 1, name : "Shiba")
let tag1 = Tag(id: 1, name: "blood A")
let tag2 = Tag(id: 2, name: "tel 1234-5678")
let photos = @[
"https://www.asahicom.jp/articles/images/AS20190719000785_commL.jpg",
"https://cdn0.mynvwm.com/wp-content/uploads/2019/02/adorable-animal-breed-1805164-e1549450482765.jpg"
]
let pochi = Pet(id: 1, category: category, name: "Pochi", photoUrls: photos, tags: @[tag1, tag2], status: Available)
let tama = Pet(id: 1, category: category, name: "Tama", photoUrls: photos, tags: @[tag1], status: Sold)

# Test Order
let myorder = Order(
id: 1,
petId: 1,
quantity: 3,
shipDate: "2019-09-08T13:53:16.603+0000",
status: Delivered,
complete: false,
)

# Test User
let jdoe = User(
id: 1,
username: "jdoe",
firstName: "John",
lastName: "Doe",
email: "[email protected]",
password: "password1234",
phone: "0011223344",
userStatus: 1
)

let asmithee = User(
id: 2,
username: "asmithee",
firstName: "Alan",
lastName: "Smithee",
email: "[email protected]",
password: "password5678",
phone: "99887766",
userStatus: 2
)

block:
let response = client.createUser(jdoe)
echo(response.code)

block:
let response = client.deleteUser("jdoe")
echo(response.code)

block:
let response = client.createUsersWithArrayInput(@[jdoe, asmithee])
echo(response.code)

block:
let response = client.createUsersWithListInput(@[jdoe, asmithee])
echo(response.code)

block:
let response = client.updateUser("jdoe", jdoe)
echo(response.code)

block:
let (api_result, response) = client.getUserByName("asmithee")
echo(repr(api_result))
echo(response.code)

block:
let (api_result, response) = client.loginUser("user", "pass")
echo(repr(api_result))
echo(response.code)

block:
let response = client.logoutUser()
echo(response.code)

block:
let (api_result, response) = client.getOrderById(1)
echo(repr(api_result))
echo(response.code)

block:
let response = client.deleteOrder("1")
echo(response.code)

block:
let (api_result, response) = client.placeOrder(myorder)
echo(repr(api_result))
echo(response.code)

block:
let (api_result, response) = client.getOrderById(1)
echo(repr(api_result))
echo(response.code)

block:
let (api_result, response) = client.getInventory()
echo(repr(api_result))
echo(response.code)

block:
let response = client.addPet(pochi)
echo(response.code)

block:
let response = client.deletePet(1, "")
echo(response.code)
discard client.addPet(pochi)

block:
let (api_result, response) = client.findPetsByStatus(@[Sold])
echo(repr(api_result))
echo(response.code)

block:
let (api_result, response) = client.findPetsByTags(@["blood A"])
echo(repr(api_result))
echo(response.code)

block:
let (api_result, response) = client.getPetById(1)
echo(repr(api_result))
echo(response.code)

block:
let response = client.updatePet(tama)
echo(response.code)
block:
let (api_result, response) = client.getPetById(1)
echo(repr(api_result))
echo(response.code)

block:
let response = client.updatePetWithForm(1, "Kuro", "pending")
echo(response.code)
block:
let (api_result, response) = client.getPetById(1)
echo(repr(api_result))
echo(response.code)

block:
let (api_result, response) = client.uploadFile(1, "kuro's photo", "kuro.jpg")
echo(repr(api_result))
echo(response.code)
23 changes: 23 additions & 0 deletions samples/client/petstore/nim/.openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
1 change: 1 addition & 0 deletions samples/client/petstore/nim/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.1.2-SNAPSHOT
54 changes: 54 additions & 0 deletions samples/client/petstore/nim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Nim API client for OpenAPI Petstore (Package: petstore)

This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.

## Overview

This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [openapi-spec](https://openapis.org) from a remote server, you can easily generate an API client.

- API version: 1.0.0
- Package version: 1.0.0
- Build package: org.openapitools.codegen.languages.NimClientCodegen

## Installation

Put the package under your project folder and add the following to the nimble file of your project:

```
import petstore
```

## Documentation for API Endpoints

All URIs are relative to *http://petstore.swagger.io/v2*

Module | Proc | HTTP request | Description
------------ | ------------- | ------------- | -------------
api_pet | addPet | **POST** /pet | Add a new pet to the store
api_pet | deletePet | **DELETE** /pet/{petId} | Deletes a pet
api_pet | findPetsByStatus | **GET** /pet/findByStatus | Finds Pets by status
api_pet | findPetsByTags | **GET** /pet/findByTags | Finds Pets by tags
api_pet | getPetById | **GET** /pet/{petId} | Find pet by ID
api_pet | updatePet | **PUT** /pet | Update an existing pet
api_pet | updatePetWithForm | **POST** /pet/{petId} | Updates a pet in the store with form data
api_pet | uploadFile | **POST** /pet/{petId}/uploadImage | uploads an image
api_store | deleteOrder | **DELETE** /store/order/{orderId} | Delete purchase order by ID
api_store | getInventory | **GET** /store/inventory | Returns pet inventories by status
api_store | getOrderById | **GET** /store/order/{orderId} | Find purchase order by ID
api_store | placeOrder | **POST** /store/order | Place an order for a pet
api_user | createUser | **POST** /user | Create user
api_user | createUsersWithArrayInput | **POST** /user/createWithArray | Creates list of users with given input array
api_user | createUsersWithListInput | **POST** /user/createWithList | Creates list of users with given input array
api_user | deleteUser | **DELETE** /user/{username} | Delete user
api_user | getUserByName | **GET** /user/{username} | Get user by user name
api_user | loginUser | **GET** /user/login | Logs user into the system
api_user | logoutUser | **GET** /user/logout | Logs out current logged in user session
api_user | updateUser | **PUT** /user/{username} | Updated user


To generate documentation with Nim DocGen, use:

```
nim doc --project --index:on petstore.nim
```

1 change: 1 addition & 0 deletions samples/client/petstore/nim/config.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const useragent* = "OpenAPI-Generator/1.0.0/nim"
Loading