GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — json-schema-validator/doc/openapi.md at master · el-psy-kongroo-d/json-schema-validator

Expand file tree

/

openapi.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
45 lines (34 loc) · 2.18 KB
/

openapi.md

Copy path

File metadata and controls

45 lines (34 loc) · 2.18 KB
Raw
Copy raw file
Download raw file
Outline
Edit and raw actions

OpenAPI Specification

The library includes support for the OpenAPI Specification.

Validating a request / response defined in an OpenAPI document

The library can be used to validate requests and responses with the use of the appropriate dialect.

Dialect Instance
https://spec.openapis.org/oas/3.0/dialect com.networknt.schema.dialect.Dialects.getOpenApi30()
https://spec.openapis.org/oas/3.1/dialect/base com.networknt.schema.dialect.Dialects.getOpenApi31()
SchemaRegistry schemaRegistry = SchemaRegistry.withDialect(Dialects.getOpenApi31());
Schema schema = schemaRegistry.getSchema(SchemaLocation.of(
        "classpath:schema/oas/3.1/petstore.yaml#/components/schemas/PetRequest"));
String input = "{\r\n"
        + "  \"petType\": \"dog\",\r\n"
        + "  \"bark\": \"woof\"\r\n"
        + "}";
List<Error> errors = schema.validate(input, InputFormat.JSON);

Validating an OpenAPI document

The library can be used to validate OpenAPI documents, however the OpenAPI meta-schema documents are not bundled with the library.

It is recommended that the relevant meta-schema documents are placed in the classpath and are mapped otherwise they will be loaded over the internet.

The following are the documents required to validate a OpenAPI 3.1 document

  • https://spec.openapis.org/oas/3.1/schema-base/2022-10-07
  • https://spec.openapis.org/oas/3.1/schema/2022-10-07
  • https://spec.openapis.org/oas/3.1/dialect/base
  • https://spec.openapis.org/oas/3.1/meta/base
Schema schema = SchemaRegistry
        .withDefaultDialect(SpecificationVersion.DRAFT_2020_12,
                builder -> builder.schemaIdResolvers(schemaIdResolvers -> schemaIdResolvers
                        .mapPrefix("https://spec.openapis.org/oas/3.1", "classpath:oas/3.1")))
        .getSchema(SchemaLocation.of("https://spec.openapis.org/oas/3.1/schema-base/2022-10-07"));
List<Error> errors = schema.validate(openApiDocument, InputFormat.JSON);
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.