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.

JSON Schema with discriminator validation

See original GitHub issue

Whenever running Portman cliOptionsFile, the Contract tests generated produce two Schema const declarations. The end result is that for every test in my Postman collection, I must either comment out or delete this second declaration because it prevents all other tests from running in Postman. The error is “SyntaxError: Identifier ‘schema’ has already been declared”.

Here’s an example of what the Tests tab includes for the contract tests in Postman: // Response Validation const schema = {"title":"PageCountryData","description":"Represents one paginated page of results of type CountryData","type":"object","properties":{"items":{"type":"array","uniqueItems":true,"minItems":1,"description":"Contains the results","items":{"title":"Country Data","type":"object","description":"API managed country data for inclusion in addresses for users, organizations and teams","properties":{"id":{"type":"integer","format":"int64","readOnly":true},"name":{"type":"string","readOnly":true},"twoDigitCode":{"type":"string","readOnly":true},"threeDigitCode":{"type":"string","readOnly":true},"positionIndex":{"type":"integer","format":"int32","readOnly":true}},"required":["id","name","twoDigitCode","threeDigitCode","positionIndex"]}},"lastPage":{"type":"boolean"},"totalCount":{"type":"integer","format":"int32"},"pageSize":{"type":"integer","format":"int32"},"page":{"type":"integer","format":"int32"},"facets":{"type":"array","uniqueItems":true,"minItems":1,"items":{"type":"object"}},"actions":{"type":"object"}},"required":["items","lastPage","totalCount","pageSize","page","facets","actions"],"x-examples":{"example-1":{"items":[{"id":0,"name":"string","twoDigitCode":"string","threeDigitCode":"string","positionIndex":0}],"lastPage":true,"totalCount":0,"pageSize":0,"page":0,"facets":[{}],"actions":{}}}}

Below this is the following:

// Response Validation const schema = {"type":"object","properties":{}}

It’s likely there’s an easy way to address this, but I have yet to find one. Thanks for your help!

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
nicklloydcommented, Aug 3, 2021

Thanks for reporting @inoclafsemaj.

Please make sure you’re using the latest version, 1.7.0 as we’ve had an issue similar to this one in the past…

If you create a public repo with your cliOptionsFile, portmanConfigFile and OpenApiSpec we can have a look to try and reproduce.

0reactions
nicklloydcommented, Dec 15, 2021

closing for now, but feel free to re-open if this remains an issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using "discriminator" keyword in JSON schema - Stack Overflow
I'm trying to have kind of polymorphic behavior in JSON. I have the following example JSON which I want to validate against the...
Read more >
Discriminators (not) changing the JSON Schema Validator ...
As discussed on the TSC on March 25th, discriminator is supposed to not affect JSON Schema validation.
Read more >
draft 2020-12 - Ajv JSON schema validator
In a simple way, JSON Schema is an object with validation keywords. ... propertyNames; unevaluatedProperties NEW: draft 2019-09; discriminator NEW: OpenAPI.
Read more >
How to use the OpenAPI discriminator - Redocly
When an API can return two or more different types of objects (aka polymorphism), use oneOf or anyOf to describe those schemas (a...
Read more >
Validating OpenAPI and JSON Schema
First, we use the jsonSchemaDialect field to set the default dialect for the document. By setting the default dialect to JSON Schema 2020-12, ......
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