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

nullable fields and reference object #552

Closed
timothyqiu opened this issue Aug 26, 2019 · 1 comment · Fixed by #556
Closed

nullable fields and reference object #552

timothyqiu opened this issue Aug 26, 2019 · 1 comment · Fixed by #556
Assignees
Labels
Milestone

Comments

@timothyqiu
Copy link

Describe the bug
If two fields in an object both reference the same schema component, and the referenced schema contains a nullable field, prism rejects the documents with Type ["string","null"] is not a valid type.

The behavior is also inconsistent between using a schema reference and writing the schema directly.

To Reproduce

  1. Given this OpenAPI document
    openapi: 3.0.0
    
    paths:
      /:
        get:
          responses:
            '200':
              content:
                application/json:
                  schema:
                    type: object
                    properties:
                      first:
                        $ref: '#/components/schemas/TestSchema'
                      second:
                        $ref: '#/components/schemas/TestSchema'
    
    components:
      schemas:
        TestSchema:
          type: object
          properties:
            output:
              type: string
              nullable: true
  2. Run this CLI command prism mock schema.yml
  3. See error ✖ fatal Type ["string","null"] is not a valid type

If the sub-schema is used directly instead of using a reference schema, it works fine:

openapi: 3.0.0

paths:
  /:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                type: object
                properties:
                  first:
                    type: object
                    properties:
                      output:
                        type: string
                        nullable: true
                  second:
                    type: object
                    properties:
                      output:
                        type: string
                        nullable: true

Expected behavior
No error is reported. Using a schema reference works the same as writing the schema directly.

Environment:

  • Library version: 3.0.4
  • OS: macOS Mojave 10.14.6
@XVincentX
Copy link
Contributor

Ok, verified. This is happening because our resolver is caching the references — trying to re-transform a schema that has been already transformed. We need to clone the schema.

Once stoplightio/http-spec#18 and propagated here in Prism, this will be fixed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants