Skip to content
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

feat(dart): dart-next generator #18970

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3749d77
initial dart-next generator
ahmednfwela Jun 19, 2024
dc4f170
Added model generation
ahmednfwela Jun 20, 2024
df44b5a
add a new overload to updateCodegenPropertyEnum to fix inner enum nam…
ahmednfwela Jun 20, 2024
b221542
update updateCodegenPropertyEnum docs
ahmednfwela Jun 20, 2024
dfcba35
formatting and comments
ahmednfwela Jun 20, 2024
c4566e6
WIP API generation
ahmednfwela Jun 21, 2024
15d98cb
WIP
ahmednfwela Jun 21, 2024
2cb8e28
finalize model generations, but XML is still WIP
ahmednfwela Jun 22, 2024
db46b60
Merge branch 'master' of github.com:OpenAPITools/openapi-generator in…
ahmednfwela Jun 22, 2024
3a1be00
update generated samples
ahmednfwela Jun 22, 2024
dd53ea5
Merge branch 'master' of github.com:OpenAPITools/openapi-generator in…
ahmednfwela Jun 23, 2024
86f5a9e
WIP generating APIs
ahmednfwela Jun 24, 2024
8fd7194
regen samples
ahmednfwela Jun 24, 2024
c1f413a
export meta instead of import
ahmednfwela Jun 24, 2024
df369b7
WIP: extract shared_infrastructure to package:openapi_infrastructure
ahmednfwela Jun 26, 2024
a27fb0a
WIP encoding multipart headers
ahmednfwela Jun 27, 2024
cd3e705
WIP API serialization
ahmednfwela Jun 29, 2024
73026ff
finalize request generation, response is WIP
ahmednfwela Jun 30, 2024
9f437eb
regen samples
ahmednfwela Jun 30, 2024
3f91384
make the generated sample compile
ahmednfwela Jun 30, 2024
4ee3423
fix forbidden APIs error
ahmednfwela Jun 30, 2024
93bf94c
WIP response generation
ahmednfwela Jun 30, 2024
ef661b5
improve handling of non-exact status code and mime types in responses
ahmednfwela Jul 1, 2024
29737bc
WIP example generation
ahmednfwela Jul 7, 2024
b3467e1
finalized model tests, WIP API tests
ahmednfwela Jul 8, 2024
851554f
refactor: Change everything to use reflections
ahmednfwela Aug 31, 2024
b42cf01
Merge branch 'master' of github.com:OpenAPITools/openapi-generator in…
ahmednfwela Aug 31, 2024
ac150e1
feat: Introduce clone, example contexts
ahmednfwela Sep 8, 2024
df54cd4
fix: incorrect oneof / anyof deserialization logic
ahmednfwela Sep 9, 2024
91d1c92
Merge branch 'master' of github.com:OpenAPITools/openapi-generator in…
ahmednfwela Jan 13, 2025
18bcae9
chore: regenerate samples
ahmednfwela Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 19 additions & 0 deletions bin/configs/dart-next-petstore-client.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
generatorName: dart-next
outputDir: samples/openapi3/client/petstore/dart/next
inputSpec: modules/openapi-generator/src/test/resources/3_0/dart/petstore.yaml
templateDir: modules/openapi-generator/src/main/resources/dart-next
additionalProperties:
hideGenerationTimestamp: "true"
pubName: petstore_api
nameMappings:
_type: $type
type_: type$
parameterNameMappings:
_type: $type
type_: type$
enumNameMappings:
s: LOWER_CASE_S
S: UPPER_CASE_S
operationIdNameMappings:
getArrayOfEnums: getFakeArrayofenums
fakeHealthGet: getFakeHealth
258 changes: 258 additions & 0 deletions docs/generators/dart-next.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
---
title: Documentation for the dart-next Generator
---

## METADATA

| Property | Value | Notes |
| -------- | ----- | ----- |
| generator name | dart-next | pass this to the generate command after -g |
| generator stability | EXPERIMENTAL | |
| generator type | CLIENT | |
| generator language | Java | |
| generator default templating engine | mustache | |
| helpTxt | Generates a dart-next client. | |

## CONFIG OPTIONS
These options may be applied as additional-properties (cli) or configOptions (plugins). Refer to [configuration docs](https://openapi-generator.tech/docs/configuration) for more details.

| Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- |
|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false|
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true|
|enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|<dl><dt>**false**</dt><dd>No changes to the enum's are made, this is the default option.</dd><dt>**true**</dt><dd>With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.</dd></dl>|false|
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C# have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|pubAuthor|Author name in generated pubspec| |Author|
|pubAuthorEmail|Email address of the author in generated pubspec| |author@homepage|
|pubDescription|Description in generated pubspec| |OpenAPI API client|
|pubHomepage|Homepage in generated pubspec| |homepage|
|pubLibrary|Library name in generated code| |openapi.api|
|pubName|Name in generated pubspec| |openapi|
|pubPublishTo|Publish_to in generated pubspec| |null|
|pubRepository|Repository in generated pubspec| |null|
|pubVersion|Version in generated pubspec| |1.0.0|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
|sourceFolder|source folder for generated code| |src|
|useEnumExtension|Allow the 'x-enum-values' extension for enums| |false|

## IMPORT MAPPING

| Type/Alias | Imports |
| ---------- | ------- |


## INSTANTIATION TYPES

| Type/Alias | Instantiated By |
| ---------- | --------------- |


## LANGUAGE PRIMITIVES

<ul class="column-ul">
<li>String</li>
<li>bool</li>
<li>double</li>
<li>int</li>
<li>num</li>
</ul>

## RESERVED WORDS

<ul class="column-ul">
<li>abstract</li>
<li>as</li>
<li>assert</li>
<li>async</li>
<li>augment</li>
<li>await</li>
<li>base</li>
<li>break</li>
<li>case</li>
<li>catch</li>
<li>class</li>
<li>const</li>
<li>continue</li>
<li>covariant</li>
<li>default</li>
<li>deferred</li>
<li>do</li>
<li>dynamic</li>
<li>else</li>
<li>enum</li>
<li>export</li>
<li>extends</li>
<li>extension</li>
<li>external</li>
<li>factory</li>
<li>false</li>
<li>final</li>
<li>finally</li>
<li>for</li>
<li>function</li>
<li>get</li>
<li>hide</li>
<li>if</li>
<li>implements</li>
<li>import</li>
<li>in</li>
<li>inout</li>
<li>interface</li>
<li>is</li>
<li>late</li>
<li>library</li>
<li>mixin</li>
<li>native</li>
<li>new</li>
<li>null</li>
<li>of</li>
<li>on</li>
<li>operator</li>
<li>out</li>
<li>part</li>
<li>patch</li>
<li>required</li>
<li>rethrow</li>
<li>return</li>
<li>sealed</li>
<li>set</li>
<li>show</li>
<li>source</li>
<li>static</li>
<li>super</li>
<li>switch</li>
<li>sync</li>
<li>this</li>
<li>throw</li>
<li>true</li>
<li>try</li>
<li>typedef</li>
<li>var</li>
<li>void</li>
<li>when</li>
<li>while</li>
<li>with</li>
<li>yield</li>
</ul>

## FEATURE SET


### Client Modification Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|BasePath|✓|ToolingExtension
|Authorizations|✗|ToolingExtension
|UserAgent|✗|ToolingExtension
|MockServer|✗|ToolingExtension

### Data Type Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Custom|✓|OAS2,OAS3
|Int32|✓|OAS2,OAS3
|Int64|✓|OAS2,OAS3
|Float|✓|OAS2,OAS3
|Double|✓|OAS2,OAS3
|Decimal|✓|ToolingExtension
|String|✓|OAS2,OAS3
|Byte|✓|OAS2,OAS3
|Binary|✓|OAS2,OAS3
|Boolean|✓|OAS2,OAS3
|Date|✓|OAS2,OAS3
|DateTime|✓|OAS2,OAS3
|Password|✓|OAS2,OAS3
|File|✓|OAS2
|Uuid|✗|
|Array|✓|OAS2,OAS3
|Null|✗|OAS3
|AnyType|✓|OAS2,OAS3
|Object|✓|OAS2,OAS3
|Maps|✓|ToolingExtension
|CollectionFormat|✓|OAS2
|CollectionFormatMulti|✓|OAS2
|Enum|✓|OAS2,OAS3
|ArrayOfEnum|✓|ToolingExtension
|ArrayOfModel|✓|ToolingExtension
|ArrayOfCollectionOfPrimitives|✓|ToolingExtension
|ArrayOfCollectionOfModel|✓|ToolingExtension
|ArrayOfCollectionOfEnum|✓|ToolingExtension
|MapOfEnum|✓|ToolingExtension
|MapOfModel|✓|ToolingExtension
|MapOfCollectionOfPrimitives|✓|ToolingExtension
|MapOfCollectionOfModel|✓|ToolingExtension
|MapOfCollectionOfEnum|✓|ToolingExtension

### Documentation Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Readme|✓|ToolingExtension
|Model|✓|ToolingExtension
|Api|✓|ToolingExtension

### Global Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Host|✓|OAS2,OAS3
|BasePath|✓|OAS2,OAS3
|Info|✓|OAS2,OAS3
|Schemes|✗|OAS2,OAS3
|PartialSchemes|✓|OAS2,OAS3
|Consumes|✓|OAS2
|Produces|✓|OAS2
|ExternalDocumentation|✓|OAS2,OAS3
|Examples|✓|OAS2,OAS3
|XMLStructureDefinitions|✗|OAS2,OAS3
|MultiServer|✗|OAS3
|ParameterizedServer|✗|OAS3
|ParameterStyling|✗|OAS3
|Callbacks|✗|OAS3
|LinkObjects|✗|OAS3

### Parameter Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Path|✓|OAS2,OAS3
|Query|✓|OAS2,OAS3
|Header|✓|OAS2,OAS3
|Body|✓|OAS2
|FormUnencoded|✓|OAS2
|FormMultipart|✓|OAS2
|Cookie|✓|OAS3

### Schema Support Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|Simple|✓|OAS2,OAS3
|Composite|✓|OAS2,OAS3
|Polymorphism|✓|OAS2,OAS3
|Union|✓|OAS3
|allOf|✓|OAS2,OAS3
|anyOf|✓|OAS3
|oneOf|✓|OAS3
|not|✗|OAS3

### Security Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|BasicAuth|✓|OAS2,OAS3
|ApiKey|✓|OAS2,OAS3
|OpenIDConnect|✗|OAS3
|BearerToken|✓|OAS3
|OAuth2_Implicit|✓|OAS2,OAS3
|OAuth2_Password|✗|OAS2,OAS3
|OAuth2_ClientCredentials|✗|OAS2,OAS3
|OAuth2_AuthorizationCode|✗|OAS2,OAS3
|SignatureAuth|✗|OAS3
|AWSV4Signature|✗|ToolingExtension

### Wire Format Feature
| Name | Supported | Defined By |
| ---- | --------- | ---------- |
|JSON|✓|OAS2,OAS3
|XML|✓|OAS2,OAS3
|PROTOBUF|✗|ToolingExtension
|Custom|✓|OAS2,OAS3
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
private boolean codegenPropertyIsNew(CodegenModel model, CodegenProperty property) {
return model.parentModel == null
? false
: model.parentModel.allVars.stream().anyMatch(p ->
: model.parentModel.allVars.stream().anyMatch(p ->
p.name.equals(property.name) &&
(p.dataType.equals(property.dataType) == false || p.datatypeWithEnum.equals(property.datatypeWithEnum) == false || p.isDiscriminator));
}
Expand Down Expand Up @@ -793,35 +793,35 @@ public ModelsMap postProcessModelsEnum(ModelsMap objs) {
// update codegen property enum with proper naming convention
// and handling of numbers, special characters
for (CodegenProperty var : cm.vars) {
updateCodegenPropertyEnum(var);
updateCodegenPropertyEnum(var,cm);
}

for (CodegenProperty var : cm.allVars) {
updateCodegenPropertyEnum(var);
updateCodegenPropertyEnum(var,cm);
}

for (CodegenProperty var : cm.nonNullableVars) {
updateCodegenPropertyEnum(var);
updateCodegenPropertyEnum(var,cm);
}

for (CodegenProperty var : cm.requiredVars) {
updateCodegenPropertyEnum(var);
updateCodegenPropertyEnum(var,cm);
}

for (CodegenProperty var : cm.optionalVars) {
updateCodegenPropertyEnum(var);
updateCodegenPropertyEnum(var,cm);
}

for (CodegenProperty var : cm.parentVars) {
updateCodegenPropertyEnum(var);
updateCodegenPropertyEnum(var,cm);
}

for (CodegenProperty var : cm.readOnlyVars) {
updateCodegenPropertyEnum(var);
updateCodegenPropertyEnum(var,cm);
}

for (CodegenProperty var : cm.readWriteVars) {
updateCodegenPropertyEnum(var);
updateCodegenPropertyEnum(var,cm);
}

}
Expand Down Expand Up @@ -6694,6 +6694,17 @@ public void updateCodegenPropertyEnum(CodegenProperty var) {
}
}

/**
* Update codegen property's enum by adding "enumVars" (with name and value),
* This method also has access to the parent CodegenModel.
*
* @param var list of CodegenProperty
* @param model parent CodegenModel
*/
public void updateCodegenPropertyEnum(CodegenProperty var, CodegenModel model) {
updateCodegenPropertyEnum(var);
}

protected String getEnumDefaultValue(String defaultValue, String dataType) {
final String enumDefaultValue;
if (isDataTypeString(dataType)) {
Expand Down
Loading
Loading