question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

String-to-model mapping fails with openapi v3

See original GitHub issue

I am working on a project that generates typescript bindings from an openapi yml, but I am hitting unexpected schema validation errors.

ERROR: Schema violation: should NOT have additional properties (components > schemas > IListBuildsResponse > properties > builds > additionalProperties)
  additionalProperty: $ref

I performed this command:

npx autorest --input-file=clients/openapi.yml --typescript --output-folder=clients/typescript-autorest/src --v3 --add-credentials

I’ve reduced the yml to the following snippet to recreate the issue:

openapi: 3.0.1
info:
  title: test
  version: 0.0.1
  description: ''
paths:
  /test:
    post:
      operationId: some_api
      parameters: []
      responses:
        default:
          description: IBulkOperationResponse
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/IListBuildsResponse
components:
  schemas:
    IBuildSummary:
      description: Public build summary returned to callers
      type: object
      properties:
        projectId:
          type: string
    IListBuildsResponse:
      type: object
      properties:
        builds:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/IBuildSummary'

Expected behavior

Generation should be successful, given the spec: http://spec.openapis.org/oas/v3.1.0#model-with-map-dictionary-properties

Additional context

Full error:

   Loading AutoRest core      'C:\Users\jtfin\.autorest\@autorest_core@3.2.4\node_modules\@autorest\core\dist' (3.2.4)
INFORMATION: > Loading AutoRest extension '@autorest/typescript' (latest->6.0.0-alpha.20210309.1)
INFORMATION: > Loading AutoRest extension '@autorest/modelerfour' (4.15.456->4.15.456)
ERROR: Unrecoverable schema validation errors were encountered in OpenAPI 3 input files.
You can use --markOpenAPI3ErrorsAsWarning to keep mark as warning and let autorest keep going.
If you believe this the validation error is incorrect, please open an issue at https://github.com/Azure/autorest
NOTE: in the future this flag will be removed and validation error will fail the pipeline.
ERROR: Schema violation: should NOT have additional properties (components > schemas > IListBuildsResponse > properties > builds > additionalProperties)
  additionalProperty: $ref
    - file:///D:/repos/backend/clients/openapi.yml:44:6
ERROR: Unrecoverable schema validation errors were encountered in OpenAPI 3 input files.
You can use --markOpenAPI3ErrorsAsWarning to keep mark as warning and let autorest keep going.
If you believe this the validation error is incorrect, please open an issue at https://github.com/Azure/autorest
NOTE: in the future this flag will be removed and validation error will fail the pipeline.
ERROR: Schema violation: should NOT have additional properties (components > schemas > IListBuildsResponse > properties > builds > additionalProperties)
  additionalProperty: $ref
    - file:///D:/repos/backend/clients/openapi.yml:44:6
Process() cancelled due to failure
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
timotheeguerincommented, Apr 13, 2021

Seems like there is an issue there as well.(flag is mark-oai3-errors-as-warnings but it will still throw the error and abort the run) Have a pr out fixing both issues and it will push a new version soon after it merges https://github.com/Azure/autorest/pull/4060

0reactions
Jtfinlaycommented, Apr 13, 2021

@timotheeguerin Works great 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

discriminator mapping should contain strings, not schema ref ...
The following program fails with the error: Error while unmarshalling property 'components' (*openapi3.Components): Error while ...
Read more >
OpenAPI Specification - Version 3.0.3 - Swagger
Keys used in YAML maps MUST be limited to a scalar string, as defined by the YAML Failsafe schema ruleset. Note: While APIs...
Read more >
OpenAPI Specification v3.1.0 | Introduction, Definitions, & More
If the discriminator value does not match an implicit or explicit mapping, no schema can be determined and validation SHOULD fail. Mapping keys ......
Read more >
OpenAPI Specification
The OpenAPI Specification Repository. ... application/vnd.github.v3.text+json application/vnd.github.v3.html+json ... For a string to model mapping:.
Read more >
OpenAPI & spring-doc not finding all mappings in a controller ...
springdoc.paths-to-match=/api/v1,/v2,/v3,/status ... This fails to match for endpoints that maybe of the form like /users/v2/ or even ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found