Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Fix: Responses description not being included in the m4 output. #370

Merged
merged 5 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
100 changes: 100 additions & 0 deletions modelerfour/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Changelog for ModelerFour

#### 4.16.0 _(unreleased)_
- **Fix** Missing description in responses. ([PR 370](https://github.com/Azure/autorest.modelerfour/pull/370))
- **Feature** Added new flag `always-create-accept-parameter` to enable/disable accept param auto generation. ([PR 366](https://github.com/Azure/autorest.modelerfour/pull/366))
- **Fix** Allow request with body being a file and `application/json` content-type. ([PR 363](https://github.com/Azure/autorest.modelerfour/pull/363))

#### 4.15.x
- Schemas with `x-ms-enum`'s `modelAsString` set to `true` will now be represented as `ChoiceSchema` even with a single value.
- `Accept` headers are now automatically added to operations having responses with content types
- Added `always-seal-x-ms-enum` settings to always create `SealedChoiceSchema` when an `x-ms-enum` is encountered

#### 4.14.x
- added `exception` SchemaContext for `usage` when used as an exception response
- changed `output` SchemaContext for `usage` to no longer include exception response uses

#### 4.13.x
- add security info (checks to see if `input.components?.securitySchemes` has any content)
- sync version of m4 and perks/codemodel == 4.13.x
- adding quality prechecker step as a way to test the OAI document for quality before modelerfour runs.
- report duplicate parents via allOf as an error.
- added `modelerfour.lenient-model-deduplication` to cause schemas with duplicated names to be renamed with an "AutoGenerated" suffix. Note that this is a *temporary* measuer that should only be used when Swaggers cannot be updated easily. This option will be removed in a future version of Modeler Four.

#### 4.12.x
- updated CI to build packages
- any is in a category in schemas
- times is a new category in schemas (not populated yet, next build)
- polymorphic payloads are not flattened (when it's the class that declares the discriminator)
- readonly is pulled from the schema if it's there
- body parameters should have the required flag set correctly
- content-type is now a header parameter (wasn't set before)
- added `modelerfour.always-create-content-type-parameter` to always get the content type parameter even when there are only one option.
- add support for x-ms-api-version extension to force enabling/disabling parameter to be treated as an api-version parameter
- the checker plugin will now halt on errors (can be disabled by `modelerfour.additional-checks: false`)
- when an enum without type is presented, if the values are all strings, assume 'string'
- flatten parents first for consistency
- added choiceType for content-type schema

#### 4.6.x
- add additional checks for empty names, collisions
- fix errant processing on APString => Apstring
- x-ms-client-name fixes on parameters
- added setting for `preserve-uppercase-max-length` to preserve uppercase words up to a certain length.

#### 4.5.x
- static linking libraries for stability
- processed all names in namer, styles can be set in config (see below):

- support overrides in namer
- static linked dependency

#### 4.4.x
- parameter grouping
- some namer changes

#### 4.3.x
- flattening (model and payload) enabled.
- properties should respect x-ms-client-name (many fixes)
- global parameters should try to be in order of original spec
- filter out 'x-ms-original' from extensions
- add serializedName for host parameters
- make sure reused global parameter is added to method too
- processed values in constants/enums a bit better, support AnySchema for no type/format
- support server variable parameters as method unless they have x-ms-parameter-location

#### 4.2.75 - bug fixes:
- add `style` to parameters to support collection format
- `potential-breaking-change` Include common paramters from oai/path #68 (requires fix from autorest-core 3.0.6160+ )
- propogate extensions from server parameters (ie, x-ms-skip-url-encoding) #61
- `potential-breaking-change` make operation groups case insensitive. #59
- `potential-breaking-change` sealedChoice/Choice selection was backwards ( was creating a sealedchoice schema for modelAsString:true and vice versa) #62
- `potential-breaking-change` drop constant schema from response, use constantschema's valueType instead. #63
- `potential-breaking-change` fix body parameter marked as required when not marked so in spec. #64

#### 4.1.60 - add missing serializedName on parameters
- query parameters should have a serializedName so that they don't rely on the cosmetic name property.


#### 4.1.58 - Breaking change:
- version bump, change your configuration to specify version `~4.1.0` or greater

```
use-extension:
"@autorest/modelerfour" : "~4.1.0"
```
- each Http operation (via `.protocol.http`) will now have a separate `path` and `uri` properties.
<br>Both are still templates, and will have parameters.
<br>The parameters for the `uri` property will have `in` set to `ParameterLocation.Uri`
<br>The parameters for the `path` property will continue to have `in` set to `ParameterLocation.Path`


- autorest-core recently added an option to aggressively deduplicate inline models (ie, ones without a name)
and modeler-four based generator will have that enabled by default. (ie `deduplicate-inline-models: true`)
<br>This may increase deduplication time on extremely large openapi models.

- this package contains the initial code for the flattener plugin, however it is not yet enabled.

- updated `@azure-tools/codemodel` package to `3.0.241`:
<br>`uri` (required) was added to `HttpRequest`
<br>`flattenedNames` (optional) was added to `Property` (in anticipation of supporting flattening)
99 changes: 1 addition & 98 deletions modelerfour/readme.md
Original file line number Diff line number Diff line change
@@ -1,103 +1,6 @@
# AutoRest Modeler Four

## Changelog:
#### 4.15.x
- Schemas with `x-ms-enum`'s `modelAsString` set to `true` will now be represented as `ChoiceSchema` even with a single value.
- `Accept` headers are now automatically added to operations having responses with content types
- Added `always-seal-x-ms-enum` settings to always create `SealedChoiceSchema` when an `x-ms-enum` is encountered

#### 4.14.x
- added `exception` SchemaContext for `usage` when used as an exception response
- changed `output` SchemaContext for `usage` to no longer include exception response uses

#### 4.13.x
- add security info (checks to see if `input.components?.securitySchemes` has any content)
- sync version of m4 and perks/codemodel == 4.13.x
- adding quality prechecker step as a way to test the OAI document for quality before modelerfour runs.
- report duplicate parents via allOf as an error.
- added `modelerfour.lenient-model-deduplication` to cause schemas with duplicated names to be renamed with an "AutoGenerated" suffix. Note that this is a *temporary* measuer that should only be used when Swaggers cannot be updated easily. This option will be removed in a future version of Modeler Four.

#### 4.12.x
- updated CI to build packages
- any is in a category in schemas
- times is a new category in schemas (not populated yet, next build)
- polymorphic payloads are not flattened (when it's the class that declares the discriminator)
- readonly is pulled from the schema if it's there
- body parameters should have the required flag set correctly
- content-type is now a header parameter (wasn't set before)
- added `modelerfour.always-create-content-type-parameter` to always get the content type parameter even when there are only one option.
- add support for x-ms-api-version extension to force enabling/disabling parameter to be treated as an api-version parameter
- the checker plugin will now halt on errors (can be disabled by `modelerfour.additional-checks: false`)
- when an enum without type is presented, if the values are all strings, assume 'string'
- flatten parents first for consistency
- added choiceType for content-type schema

#### 4.6.x
- add additional checks for empty names, collisions
- fix errant processing on APString => Apstring
- x-ms-client-name fixes on parameters
- added setting for `preserve-uppercase-max-length` to preserve uppercase words up to a certain length.

#### 4.5.x
- static linking libraries for stability
- processed all names in namer, styles can be set in config (see below):

- support overrides in namer
- static linked dependency

#### 4.4.x
- parameter grouping
- some namer changes

#### 4.3.x
- flattening (model and payload) enabled.
- properties should respect x-ms-client-name (many fixes)
- global parameters should try to be in order of original spec
- filter out 'x-ms-original' from extensions
- add serializedName for host parameters
- make sure reused global parameter is added to method too
- processed values in constants/enums a bit better, support AnySchema for no type/format
- support server variable parameters as method unless they have x-ms-parameter-location

#### 4.2.75 - bug fixes:
- add `style` to parameters to support collection format
- `potential-breaking-change` Include common paramters from oai/path #68 (requires fix from autorest-core 3.0.6160+ )
- propogate extensions from server parameters (ie, x-ms-skip-url-encoding) #61
- `potential-breaking-change` make operation groups case insensitive. #59
- `potential-breaking-change` sealedChoice/Choice selection was backwards ( was creating a sealedchoice schema for modelAsString:true and vice versa) #62
- `potential-breaking-change` drop constant schema from response, use constantschema's valueType instead. #63
- `potential-breaking-change` fix body parameter marked as required when not marked so in spec. #64

#### 4.1.60 - add missing serializedName on parameters
- query parameters should have a serializedName so that they don't rely on the cosmetic name property.


#### 4.1.58 - Breaking change:
- version bump, change your configuration to specify version `~4.1.0` or greater

```
use-extension:
"@autorest/modelerfour" : "~4.1.0"
```
- each Http operation (via `.protocol.http`) will now have a separate `path` and `uri` properties.
<br>Both are still templates, and will have parameters.
<br>The parameters for the `uri` property will have `in` set to `ParameterLocation.Uri`
<br>The parameters for the `path` property will continue to have `in` set to `ParameterLocation.Path`


- autorest-core recently added an option to aggressively deduplicate inline models (ie, ones without a name)
and modeler-four based generator will have that enabled by default. (ie `deduplicate-inline-models: true`)
<br>This may increase deduplication time on extremely large openapi models.

- this package contains the initial code for the flattener plugin, however it is not yet enabled.

- updated `@azure-tools/codemodel` package to `3.0.241`:
<br>`uri` (required) was added to `HttpRequest`
<br>`flattenedNames` (optional) was added to `Property` (in anticipation of supporting flattening)



# Contributing
## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
Expand Down
4 changes: 4 additions & 0 deletions modelerfour/src/modeler/modelerfour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,8 @@ export class ModelerFour {
const rsp = new Response({
extensions: this.interpret.getExtensionProperties(response),
});
rsp.language.default.description = response.description;

const headers = new Array<HttpHeader>();
for (const { key: header, value: hh } of this.resolveDictionary(response.headers)) {
this.use(hh.schema, (n, sch) => {
Expand Down Expand Up @@ -2007,6 +2009,7 @@ export class ModelerFour {
const rsp = new BinaryResponse({
extensions: this.interpret.getExtensionProperties(response),
});
rsp.language.default.description = response.description;
rsp.protocol.http = SetType(HttpBinaryResponse, {
statusCodes: [responseCode],
knownMediaType: knownMediaType,
Expand Down Expand Up @@ -2053,6 +2056,7 @@ export class ModelerFour {
extensions: this.interpret.getExtensionProperties(response),
nullable: schema.nullable,
});
rsp.language.default.description = response.description;

rsp.protocol.http = SetType(HttpResponse, {
statusCodes: [responseCode],
Expand Down
43 changes: 43 additions & 0 deletions modelerfour/test/modeler/modelerfour.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1069,4 +1069,47 @@ describe("Modeler", () => {
const choices1 = (<SealedChoiceSchema>contentType1Schema).choices.map((c) => c.value).sort();
expect(choices1).toEqual(["image/bmp", "image/png"]);
});

describe("Responses", () => {
it("include the response description for no content response", async () => {
const spec = createTestSpec();
addOperation(spec, "/test", {
get: {
responses: {
"204": {
description: "Foo bar test description",
},
},
},
});

const codeModel = await runModeler(spec);

const value = codeModel.operationGroups[0]?.operations[0]?.responses?.[0];
expect(value).not.toBeNull();
expect(value?.language.default.description).toEqual("Foo bar test description");
});

it("include the response description for no schema response", async () => {
const spec = createTestSpec();
addOperation(spec, "/test", {
get: {
responses: {
"200": {
description: "Foo bar test description",
content: {
"application/json": { schema: { type: "object" } },
},
},
},
},
});

const codeModel = await runModeler(spec);

const value = codeModel.operationGroups[0]?.operations[0]?.responses?.[0];
expect(value).not.toBeNull();
expect(value?.language.default.description).toEqual("Foo bar test description");
});
});
});
4 changes: 2 additions & 2 deletions modelerfour/test/scenarios/expected/head/modeler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ operationGroups:
language: !<!Languages>
default:
name: ''
description: ''
description: Upload successful
protocol: !<!Protocols>
http: !<!HttpResponse>
statusCodes:
- '200'
- '204'
timotheeguerin marked this conversation as resolved.
Show resolved Hide resolved
language: !<!Languages>
default:
name: File
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"required": true
},
"responses": {
"200": {
"description": "Cowbell was added."
"204": {
"description": "Upload successful"
}
}
}
Expand Down