NAME

JSON::Schema::Modern::Document::OpenAPI - One OpenAPI v3.1 document

VERSION

version 0.092

SYNOPSIS

use JSON::Schema::Modern::Document::OpenAPI;

my $openapi_document = JSON::Schema::Modern::Document::OpenAPI->new(
  canonical_uri => 'https://example.com/v1/api',
  schema => decode_json(<<JSON),
{
"openapi": "3.1",
"info": {
  "title": "my title",
  "version": "1.2.3"
},
"components": {
},
"paths": {
  "/foo": {
    "get": {}
  },
  "/foo/{foo_id}": {
    "post": {}
  }
}
}
JSON
  metaschema_uri => 'https://example.com/my_custom_metaschema',
);

DESCRIPTION

Provides structured parsing of an OpenAPI document, suitable as the base for more tooling such as request and response validation, code generation or form generation.

The provided document must be a valid OpenAPI document, as specified by the schema identified by https://spec.openapis.org/oas/3.1/schema-base/2025-02-13 (which is a wrapper around https://spec.openapis.org/oas/3.1/schema/2025-02-13), and the OpenAPI v3.1.x specification.

CONSTRUCTOR ARGUMENTS

Unless otherwise noted, these are also available as read-only accessors.

schema

The actual raw data representing the OpenAPI document. Required.

evaluator

A JSON::Schema::Modern object which is used for parsing the schema of this document. This is the object that holds all other schemas that may be used for parsing: that is, metaschemas that define the structure of the document.

Optional, unless you are using custom metaschemas for your OpenAPI document or embedded JSON Schemas (in which case you should define the evaluator first and call "add_schema" in JSON::Schema::Modern for each customization, before calling this constructor).

This argument is not saved after object construction, so it is not available as an accessor. However, if this document object was constructed via a call to "new" in OpenAPI::Modern, it will be saved on that object for use during request and response validation, so it is expected that the evaluator object should also hold the other documents that are needed for runtime evaluation (which may be other JSON::Schema::Modern::Document::OpenAPI objects).

canonical_uri

This is the identifier that the document is known by, which is used to resolve any relative $ref keywords in the document (unless overridden by a subsequent $id in a schema). See "https://spec.openapis.org/oas/v3.1#relative-references-in-api-description-uris" in §4.6. It is strongly recommended that this URI is absolute.

See also "retrieval_uri".

metaschema_uri

The URI of the schema that describes the OpenAPI document itself. Defaults to https://spec.openapis.org/oas/3.1/schema-base/2025-02-13 when the "https://spec.openapis.org/oas/v3.1#fixed-fields" in jsonSchemaDialect is not changed from its default; otherwise defaults to a dynamically generated metaschema that uses the correct value of jsonSchemaDialect, so you don't need to write one yourself.

Note that both the schemas described by metaschema_uri and by the jsonSchemaDialect keyword (if you are using custom schemas) should be loaded into the evaluator in advance with "add_schema" in JSON::Schema::Modern, and then this evaluator should be provided to the OpenAPI::Modern constructor.

METHODS

This class inherits all methods from JSON::Schema::Modern::Document. In addition:

retrieval_uri

Also available as "original_uri" in JSON::Schema::Modern::Document, this is known as the "retrieval URI" in the OAS specification: the URL the document was originally sourced from, or the URI that was used to add the document to the OpenAPI::Modern instance.

In OpenAPI version 3.1.x, this is the same as "canonical_uri".

get_operationId_path

Returns the json pointer location of the operation containing the provided operationId (suitable for passing to $document->get(..)), or undef if the operation does not exist in the document.

SEE ALSO

SUPPORT

Bugs may be submitted through https://github.com/karenetheridge/OpenAPI-Modern/issues.

I am also usually active on irc, as 'ether' at irc.perl.org and irc.libera.chat.

You can also find me on the JSON Schema Slack server and OpenAPI Slack server, which are also great resources for finding help.

AUTHOR

Karen Etheridge <ether@cpan.org>

COPYRIGHT AND LICENCE

This software is copyright (c) 2021 by Karen Etheridge.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Some schema files have their own licence, in share/oas/LICENSE.