Open API : Generate properties schema JSON from yaml file for adding validation on UI

Viewed 670

From swagger file we need to extract properties like

  • minimum, maximium, maxLength, minLength, pattern

in a json format, so that it can be used inside the javascript code to do validation.

We are uisng npx @openapitools/openapi-generator-cli to generate the interface and axios call, dident find config option we can pass to it to extract the properties also.

https://openapi-generator.tech/docs/generators/typescript-axios/

If there any we can generate the JSON with properties from yaml file.

Thank you.

1 Answers

After some more look up found following package generates the properties JSON from swagger/openapi yaml file

  1. openapi-typescript-codegen and passing flag exportSchemas true
  2. openapi2jsonschema https://github.com/instrumenta/openapi2jsonschema

Using openapi2jsonschema as it gives more properties than openapi-typescript-codegen like default values.

Then we need to import the JSON and access the properties.

Related