-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Add Nim client code generator #3879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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 18d367a
Add some codes
hokamoto 9639569
Add some codes
hokamoto a999b5e
Add some codes
hokamoto 5d73b11
Add some codes
hokamoto 3880039
Add some codes
hokamoto c48f0a0
First version of Nim Client
hokamoto c5e4713
Add some codes
hokamoto feb96b1
Add some codes
hokamoto 5fdc0ab
Add some codes
hokamoto ae33303
Add some codes
hokamoto ba35508
Add some codes
hokamoto fc74ece
[Dart] Fix README template and update testing doco (#3809)
nickmeinhold 7b4a201
Support custom git repository (#3757)
qmuntal 2451702
Add links to article and video (#3820)
wing328 9ef73eb
Better Go code format (#3819)
wing328 c90c6c8
Add gRPC Protobuf schema generator (#3818)
wing328 bdfed92
1792 fix remote spec handling and hash calculation (#3440)
7c5cfb7
fixed bug where nullApi.java would be generated. Instead, generated …
bensimpson-ch 99eb680
Revert "1792 fix remote spec handling and hash calculation (#3440)"
wing328 ac1f19d
Add nickmeinhold to Dart technical committee (#3830)
wing328 9cbcebc
Bug #2845 typescript angular inheritance (#3812)
mnahkies 9ba0dd0
fix warnings in csharp-netcore client (#3831)
wing328 5d21a8f
Add missing files to the form request (#3834)
etherealjoy 8c637fb
[client][go] avoid duplicated reflect imports (#3847)
qmuntal f26f726
Following up for #3440 (1792 fix remote spec handling and hash calcul…
fuj1g0n 4a1eb91
Add a link (#3850)
ackintosh 3228ca2
Add Element AI to the list (#3856)
wing328 2fb08fb
maven-plugin-plugin 3.6.0 (#3854)
sullis 221443a
[Java][okhttp-gson] fix failure to deserialize floats (#3846)
bensimpson-ch adf1297
Adds Http Info To Dart Api (#3851)
austbot 86adb0a
[C++][Pistache] Add missing setter for arrays (#3837)
muttleyxd 82f00f2
typescript-inversify: improve check for required parameters, support …
bodograumann 0f10987
[typescript-angular] allow empty string basePath (#3489)
martinnovak bf441c2
Fix/r/serialization fix and minor 3xx resp fix (#3817)
Ramanth e51ffbe
typescript-axios: Fix baseoptions (#3866)
7474 0396bb4
Rename gRPC generator to "protobuf-schema" (#3864)
wing328 3dd0ebd
Prepare v4.1.2 release (#3873)
wing328 58ec946
fix version in readme
macjohnny 580ca11
BugFix #2053 Spring Boot fails to parse LocalDate query parameter (#3…
peyerroger fbb3b27
update doc, samples (#3875)
wing328 549fc8f
update stable release
wing328 bface47
Update the batch for Windows
hokamoto 5a28be0
Merge branch 'nim-client' of github.com:hokamoto/openapi-generator in…
hokamoto 19cc13b
Merge remote-tracking branch 'upstream/master' into nim-client
hokamoto 2db44c7
Add a test snippet
hokamoto bcec49b
Update ensure-up-to-date
hokamoto 7276034
Add Nim to README.md
hokamoto 090875b
Ran ensure-up-to-date to pass CircleCI tests
hokamoto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
First version of Nim Client
- Loading branch information
commit f2663803c4517423e6c536d9fe3008076073dcff
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #!/bin/sh | ||
|
|
||
| SCRIPT="$0" | ||
|
|
||
| while [ -h "$SCRIPT" ] ; do | ||
| ls=$(ls -ld "$SCRIPT") | ||
| link=$(expr "$ls" : '.*-> \(.*\)$') | ||
| if expr "$link" : '/.*' > /dev/null; then | ||
| SCRIPT="$link" | ||
| else | ||
| SCRIPT=$(dirname "$SCRIPT")/"$link" | ||
| fi | ||
| done | ||
|
|
||
| if [ ! -d "${APP_DIR}" ]; then | ||
| APP_DIR=$(dirname "$SCRIPT")/.. | ||
| APP_DIR=$(cd "${APP_DIR}"; pwd) | ||
| fi | ||
|
|
||
| executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" | ||
|
|
||
| if [ ! -f "$executable" ] | ||
| then | ||
| mvn clean package | ||
| 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 -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g nim -o samples/client/petstore/nim" | ||
| ags="$@ generate -DdebugModels -t modules/openapi-generator/src/main/resources/nim-client -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g nim -o samples/client/petstore/nim" | ||
|
|
||
| java ${JAVA_OPTS} -jar ${executable} ${ags} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar | ||
|
|
||
| If Not Exist %executable% ( | ||
| mvn clean package | ||
| ) | ||
|
|
||
| REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties | ||
| set ags=generate --artifact-id "nim-petstore-client" -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g nim -o samples\client\petstore\nim | ||
|
|
||
| java %JAVA_OPTS% -jar %executable% %ags% |
181 changes: 181 additions & 0 deletions
181
.../openapi-generator/src/main/java/org/openapitools/codegen/languages/NimClientCodegen.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,181 @@ | ||
| package org.openapitools.codegen.languages; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add the copyright header in another PR. |
||
|
|
||
| import io.swagger.v3.oas.models.media.ArraySchema; | ||
| import io.swagger.v3.oas.models.media.Schema; | ||
| import org.openapitools.codegen.*; | ||
| import org.openapitools.codegen.utils.ModelUtils; | ||
| import org.openapitools.codegen.utils.StringUtils; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.io.File; | ||
| import java.util.Arrays; | ||
| import java.util.HashSet; | ||
| import java.util.Map; | ||
|
|
||
| import static org.openapitools.codegen.utils.StringUtils.camelize; | ||
|
|
||
| public class NimClientCodegen extends DefaultCodegen implements CodegenConfig { | ||
| public static final String PROJECT_NAME = "projectName"; | ||
|
|
||
| static Logger LOGGER = LoggerFactory.getLogger(NimClientCodegen.class); | ||
|
|
||
| public CodegenType getTag() { | ||
| return CodegenType.CLIENT; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return "nim"; | ||
| } | ||
|
|
||
| public String getHelp() { | ||
| return "Generates a nim client."; | ||
| } | ||
|
|
||
| public NimClientCodegen() { | ||
| super(); | ||
|
|
||
| outputFolder = "generated-code" + File.separator + "nim"; | ||
| modelTemplateFiles.put("model.mustache", ".nim"); | ||
| apiTemplateFiles.put("api.mustache", ".nim"); | ||
| embeddedTemplateDir = templateDir = "nim-client"; | ||
| apiPackage = File.separator + "apis"; | ||
| modelPackage = File.separator + "models"; | ||
| supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); | ||
|
|
||
| setReservedWordsLowerCase( | ||
| Arrays.asList( | ||
| "addr", "and", "as", "asm", | ||
| "bind", "block", "break", | ||
| "case", "cast", "concept", "const", "continue", "converter", | ||
| "defer", "discard", "distinct", "div", "do", | ||
| "elif", "else", "end", "enum", "except", "export", | ||
| "finally", "for", "from", "func", | ||
| "if", "import", "in", "include", "interface", "is", "isnot", "iterator", | ||
| "let", | ||
| "macro", "method", "mixin", "mod", | ||
| "nil", "not", "notin", | ||
| "object", "of", "or", "out", | ||
| "proc", "ptr", | ||
| "raise", "ref", "return", | ||
| "shl", "shr", "static", | ||
| "template", "try", "tuple", "type", | ||
| "using", | ||
| "var", | ||
| "when", "while", | ||
| "xor", | ||
| "yield" | ||
| ) | ||
| ); | ||
|
|
||
| defaultIncludes = new HashSet<String>( | ||
| Arrays.asList( | ||
| "array" | ||
| ) | ||
| ); | ||
|
|
||
| languageSpecificPrimitives = new HashSet<String>( | ||
| Arrays.asList( | ||
| "int", | ||
| "int8", | ||
| "int16", | ||
| "int32", | ||
| "int64", | ||
| "uint", | ||
| "uint8", | ||
| "uint16", | ||
| "uint32", | ||
| "uint64", | ||
| "float", | ||
| "float32", | ||
| "float64", | ||
| "bool", | ||
| "char", | ||
| "string", | ||
| "cstring", | ||
| "pointer") | ||
| ); | ||
|
|
||
| typeMapping.clear(); | ||
| typeMapping.put("integer", "int"); | ||
| typeMapping.put("long", "int64"); | ||
| typeMapping.put("number", "float"); | ||
| typeMapping.put("float", "float"); | ||
| typeMapping.put("double", "float64"); | ||
| typeMapping.put("boolean", "bool"); | ||
| typeMapping.put("UUID", "string"); | ||
| typeMapping.put("URI", "string"); | ||
| typeMapping.put("date", "string"); | ||
| typeMapping.put("DateTime", "string"); | ||
| typeMapping.put("password", "string"); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, Object> postProcessModels(Map<String, Object> objs) { | ||
| return postProcessModelsEnum(objs); | ||
| } | ||
|
|
||
| @Override | ||
| public String escapeReservedWord(String name) { | ||
| if (this.reservedWordsMappings().containsKey(name)) { | ||
| return this.reservedWordsMappings().get(name); | ||
| } | ||
| return "var" + StringUtils.camelize(name, false); | ||
| } | ||
|
|
||
| @Override | ||
| public String toModelImport(String name) { | ||
| if (importMapping.containsKey(name)) { | ||
| return StringUtils.camelize(importMapping.get(name), true); | ||
| } else { | ||
| return StringUtils.camelize(name, true); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public String toModelFilename(String name) { | ||
| return StringUtils.camelize(name, true); | ||
| } | ||
|
|
||
| @Override | ||
| public String getTypeDeclaration(Schema p) { | ||
| if (ModelUtils.isArraySchema(p)) { | ||
| ArraySchema ap = (ArraySchema) p; | ||
| Schema inner = ap.getItems(); | ||
| if (inner == null) { | ||
| return null; | ||
| } | ||
| return "seq[" + getTypeDeclaration(inner) + "]"; | ||
| } | ||
|
|
||
| String schemaType = getSchemaType(p); | ||
| if (typeMapping.containsKey(schemaType)) { | ||
| return typeMapping.get(schemaType); | ||
| } | ||
|
|
||
| return schemaType; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean needToImport(String type) { | ||
| if (defaultIncludes.contains(type)) { | ||
| return false; | ||
| } else if (languageSpecificPrimitives.contains(type)) { | ||
| return false; | ||
| } else if (typeMapping.containsKey(type) && languageSpecificPrimitives.contains(typeMapping.get(type))) { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public String toEnumName(CodegenProperty property) { | ||
| return StringUtils.camelize(property.name, false); | ||
| } | ||
|
|
||
| @Override | ||
| public String toEnumVarName(String name, String datatype) { | ||
| return StringUtils.camelize(name, false); | ||
| } | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
modules/openapi-generator/src/main/resources/nim-client/README.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Documentation for {{appName}} |
1 change: 1 addition & 0 deletions
1
modules/openapi-generator/src/main/resources/nim-client/api.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # |
9 changes: 9 additions & 0 deletions
9
modules/openapi-generator/src/main/resources/nim-client/model.mustache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| {{#imports}}import "{{import}}" | ||
| {{/imports}}{{#models}}{{#model}}{{#vars}}{{#isEnum}} | ||
| type {{enumName}}* {.pure.} = enum{{#allowableValues}}{{#enumVars}} | ||
| {{name}}{{/enumVars}}{{/allowableValues}} | ||
| {{/isEnum}}{{/vars}} | ||
| type {{{classname}}}* = ref object | ||
| ## {{{description}}}{{#vars}} | ||
| {{{name}}}: {{#isEnum}}{{{enumName}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#description}} ## {{{description}}}{{/description}}{{/vars}} | ||
| {{/model}}{{/models}} |
29 changes: 29 additions & 0 deletions
29
...enapi-generator/src/test/java/org/openapitools/codegen/nim/NimClientCodegenModelTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package org.openapitools.codegen.nim; | ||
|
|
||
| import org.openapitools.codegen.*; | ||
| import org.openapitools.codegen.languages.NimClientCodegen; | ||
| import io.swagger.models.*; | ||
| import io.swagger.models.properties.*; | ||
|
|
||
| import org.testng.Assert; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| @SuppressWarnings("static-method") | ||
| public class NimClientCodegenModelTest { | ||
|
|
||
| @Test(description = "convert a simple java model") | ||
| public void simpleModelTest() { | ||
| final Model model = new ModelImpl() | ||
| .description("a sample model") | ||
| .property("id", new LongProperty()) | ||
| .property("name", new StringProperty()) | ||
| .required("id") | ||
| .required("name"); | ||
| final DefaultCodegen codegen = new NimClientCodegen(); | ||
|
|
||
| // TODO: Complete this test. | ||
| Assert.fail("Not implemented."); | ||
| } | ||
|
|
||
| } | ||
|
|
34 changes: 34 additions & 0 deletions
34
...api-generator/src/test/java/org/openapitools/codegen/nim/NimClientCodegenOptionsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package org.openapitools.codegen.nim; | ||
|
|
||
| import org.openapitools.codegen.AbstractOptionsTest; | ||
| import org.openapitools.codegen.CodegenConfig; | ||
| import org.openapitools.codegen.languages.NimClientCodegen; | ||
| import org.openapitools.codegen.options.NimClientCodegenOptionsProvider; | ||
|
|
||
| import mockit.Expectations; | ||
| import mockit.Tested; | ||
|
|
||
| public class NimClientCodegenOptionsTest extends AbstractOptionsTest { | ||
|
|
||
| @Tested | ||
| private NimClientCodegen codegen; | ||
|
|
||
| public NimClientCodegenOptionsTest() { | ||
| super(new NimClientCodegenOptionsProvider()); | ||
| } | ||
|
|
||
| @Override | ||
| protected CodegenConfig getCodegenConfig() { | ||
| return codegen; | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| @Override | ||
| protected void setExpectations() { | ||
| // TODO: Complete options | ||
| new Expectations(codegen) {{ | ||
|
|
||
| }}; | ||
| } | ||
| } | ||
|
|
19 changes: 19 additions & 0 deletions
19
...es/openapi-generator/src/test/java/org/openapitools/codegen/nim/NimClientCodegenTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package org.openapitools.codegen.nim; | ||
|
|
||
| import org.openapitools.codegen.*; | ||
| import org.openapitools.codegen.languages.NimClientCodegen; | ||
| import io.swagger.models.*; | ||
| import io.swagger.parser.SwaggerParser; | ||
| import org.testng.Assert; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| public class NimClientCodegenTest { | ||
|
|
||
| NimClientCodegen codegen = new NimClientCodegen(); | ||
|
|
||
| @Test | ||
| public void shouldSucceed() throws Exception { | ||
| // TODO: Complete this test. | ||
| Assert.fail("Not implemented."); | ||
macjohnny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
31 changes: 31 additions & 0 deletions
31
...rator/src/test/java/org/openapitools/codegen/options/NimClientCodegenOptionsProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package org.openapitools.codegen.options; | ||
|
|
||
| import org.openapitools.codegen.CodegenConstants; | ||
| import org.openapitools.codegen.languages.NimClientCodegen; | ||
|
|
||
| import com.google.common.collect.ImmutableMap; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class NimClientCodegenOptionsProvider implements OptionsProvider { | ||
| public static final String PROJECT_NAME_VALUE = "OpenAPI"; | ||
|
|
||
| @Override | ||
| public String getLanguage() { | ||
| return "nim"; | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, String> createOptions() { | ||
| ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>(); | ||
| return builder | ||
| .put(NimClientCodegen.PROJECT_NAME, PROJECT_NAME_VALUE) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isServer() { | ||
| return false; | ||
| } | ||
| } | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.