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

how to use nullable attribute in examples? #49

Closed
sybrands-place opened this issue Nov 17, 2021 · 4 comments
Closed

how to use nullable attribute in examples? #49

sybrands-place opened this issue Nov 17, 2021 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@sybrands-place
Copy link

sybrands-place commented Nov 17, 2021

How can I get a null example value for a type string? (while using OpenAPI 3.0.3)

"errorDescription" : {
   "title" : "The errorDescription schema",
   "type" : "string",
   "nullable": true
}

When I use the example above, I get "errorDescription": "string", as a result

When I add "default": null there's a [FATAL] Error while mocking schema ...

(maybe updating ajv is a solution? https://ajv.js.org/v6-to-v8-migration.html)

@jormaechea
Copy link
Owner

Hi @sybrands-place, can you provide a minimal OpenAPI schema to reproduce the issue? This way I can find a solution faster.

@jormaechea jormaechea added the needs information Issue needs more information label Nov 27, 2021
@sybrands-place
Copy link
Author

sybrands-place commented Nov 29, 2021

Sure, here's an example:

  "openapi": "3.0.1",
  "info": {
    "title": "Dummy OpenAPI Mock server with nullable String",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "http://localhost:8080",
      "description": "Swagger Mock Server URL"
    }
  ],
  "paths": {
    "/dummy": {
      "get": {
        "summary": "Get dummy information",
        "operationId": "getDummyInformation",
        "responses": {
          "200": {
          "description": "OK",
          "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [ 
                    "contactpersonResponse",
                    "additionalProperties"
                  ],
                  "properties": {
                    "dummyDescription": {
                      "title": "The dummyDescription schema",
                      "type": "string",
                      "nullable": true
                    },
                    "extraDescription": {
                      "title": "The extraDescription schema",
                      "type": "object",
                      "default": {}
                    }
                  },
                  "example": {
                    "dummyDescription": null,
                    "extraDescription": {}
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

In this case with an example it works (i.e. dummyDescription becomes null), but if you remove the example the value for dummyDescription becomes "string". Perhaps this is how it should work, that it only works if you provide an example? I tried setting the default value to null, but as mentioned before then there's an error message.

EDIT: my original post might be misleading together with this message. Then it didn't work even with an example, but it was because the example was for a child element and not the complete element. So I guess that's clear to me now. I only need the verification that default doesn't work with a nullable String. Thanks for suggesting to make a simpler example, that helped! ;)

@jormaechea jormaechea added enhancement New feature or request and removed needs information Issue needs more information labels Dec 22, 2021
@jormaechea jormaechea self-assigned this Dec 22, 2021
@jormaechea
Copy link
Owner

@sybrands-place sorry for the delay, I've been really busy. I'm now working on allowing null examples and default values, it should be ready soon.

@jormaechea
Copy link
Owner

Feature released in v1.10.0

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

No branches or pull requests

2 participants