VP-3148: Fix issues after migration to Open API v3 and latest Swashbuckle #441
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.
Problems
We have a few problems because of migration to Open API v3 and latest Swashbuckle:
[FromBody]attributeOut of scope of this PR:
2. Because of bug in OpenAPI.NET library which Swashbuckle use for API schema generation and conversion from v2 to v3. The workaround for some tools is to use same vendor extensions (
x-schema properties) as we use for v3 (see later). Extensibility of request body parameter in v2 also isn't supported currently, I made PR to OpenAPI.NET to support it.5. I don't think it's something important just because it will make these parameters as union with
undefined(string | undefined, for example). It allow do more, than possible, not less. So I created VP-3175 about that.Solution
1.1.
x-nameandx-positionforNSwag1.2
x-codegen-request-body-nameforSwagger Codegen. Position isn't support and not neccessary here because Swagger Codegen always put body to the end of generated methods, even for Open API v2.1.3.
x-ms-requestBody-nameandx-ms-requestBody-indexfor AutoRest.requestBodyoccurrences in schema as requiredProposed changes
NameAndOrderRequestBodyparameter toappSettings.jsoninSwagger:Schemasection. If it's enabled,ParameterOrderFilterandNameAndOrderRequestBodyFilterfilers for Swashbuckle will add vendor extensions to support body naming and positionning.https://github.com/VirtoCommerce/vc-storefront-core/pull/441/files#diff-3b8759d90ee0adf1adf31373f4c91f68R357-R358
https://github.com/VirtoCommerce/vc-storefront-core/pull/441/files#diff-94cddb6036b2fc6ff8d4aebebe23c31e
https://github.com/VirtoCommerce/vc-storefront-core/pull/441/files#diff-63affde52279701e934521b33cb972ef
OpenApiSpecificationVersionparameter inSwagger:Schemasection ofappSettings.jsonwhich allow you to select which schema version should be produced. Unfortunately, we can't add new API version with new Open API specification version support - all versions will be generated with the same Open API specification.https://github.com/VirtoCommerce/vc-storefront-core/pull/441/files#diff-2f1bd9bddcbb37bce32c91dcbd59948e
https://github.com/VirtoCommerce/vc-storefront-core/pull/441/files#diff-bbef13df0bbb66cd265aff04d91e7476R9
https://github.com/VirtoCommerce/vc-storefront-core/pull/441/files#diff-3b8759d90ee0adf1adf31373f4c91f68R429-R434
UseAllOfToExtendReferenceSchemasschema option which will make desired behavior.https://github.com/VirtoCommerce/vc-storefront-core/pull/441/files#diff-3b8759d90ee0adf1adf31373f4c91f68R367
RequireRequestBodyFilteradded to make allrequestBodyoccurrences in schema as requiredhttps://github.com/VirtoCommerce/vc-storefront-core/pull/441/files#diff-3b8759d90ee0adf1adf31373f4c91f68R359
https://github.com/VirtoCommerce/vc-storefront-core/pull/441/files#diff-602d549f760206cd3d0f0882fcfe48ec
AddSwaggerGenNewtonsoftSupportmethod called during services configuration due to Swashbuckle readme. It also replace ourOptionalParametersFilterandNewtonsoftJsonIgnoreFilterand produce more correct schema - for, example it exclude from schema proeprties marked with[IgnoreDataMember]likeCustomer,CurrencyorLanguageofCartSearchCriteriaAdditional context (optional)