Reference

Objects

Every object of Ark4ne\OpenApiWriter\Objects, its constructors and its methods.

Every class is in Ark4ne\OpenApiWriter\Objects. Every method returns a modified copy. T ... is variadic; for a list or a map, the field name replaces and add + the field name appends. 3.1+ and 3.2 mark what older versions cannot write. A method taking an enum also takes its string value.

Common methods

MethodPurpose
static create(?string $objectId = null)New empty object; the objectId is its key in the parent
objectId(?string $objectId)Copy with another key
without(string $field)Copy without the field
has(string $field): boolWhether the field is set
$object->fieldRead a field; null when unset
toArray($version, $extensions), toJson($version, $flags, $extensions), toYaml($version, $extensions)Write the object
x(string $name, mixed $value), withoutX(string $name)Extensions, on every object but Reference and SecurityRequirement

Document

OpenApi

MethodNotes
openapi(Version|string|null)Default version for writing and validating
self(?string)3.2 $self
info(?Info)Required
jsonSchemaDialect(?string)3.1+
servers(Server ...)
paths(PathItem ...)objectId = path
webhooks(PathItemContract ...)3.1+ objectId = webhook name
components(?Components)
security(SecurityRequirement ...)Alternatives
tags(Tag ...)
externalDocs(?ExternalDocumentation)

json_encode($openApi) writes it for its declared version.

Info, Contact, License

ObjectMethods
Infotitle(?string) (required), summary(?string) 3.1+, description(?string), termsOfService(?string), contact(?Contact), license(?License), version(?string) (required)
Contactname(?string), url(?string), email(?string)
Licensename(?string) (required), identifier(?string) 3.1+, url(?string); identifier and url are exclusive

Server, ServerVariable

ObjectMethods
Serverurl(?string) (required), description(?string), name(?string) 3.2, variables(ServerVariable ...)
ServerVariable::create('region')enum(string ...), default(?string) (required), description(?string)

Tag, ExternalDocumentation

ObjectMethods
Tagname(?string) (required, not set by create()), summary(?string) 3.2, description(?string), externalDocs(?ExternalDocumentation), parent(?string) 3.2, kind(?string) 3.2
ExternalDocumentationdescription(?string), url(?string) (required)

Paths and operations

PathItem

PathItem::create('/users/{id}'); the objectId is the path, the webhook name or the callback expression.

MethodNotes
operations(Operation ...)Each operation under its method (its objectId)
get(), put(), post(), delete(), options(), head(), patch(), trace()One ?Operation each
query(?Operation)3.2
additionalOperations(Operation ...)3.2 other methods: Operation::create('COPY')
ref(?string)$ref to a path item defined elsewhere
summary(?string), description(?string)
servers(Server ...)
parameters(ParameterContract ...)Shared by every operation

Operation

Shortcuts: Operation::get(), put(), post(), delete(), options(), head(), patch(), trace(), query()3.2; Operation::create('COPY') for additionalOperations.

MethodNotes
tags(string ...)Tag names
summary(?string), description(?string)
externalDocs(?ExternalDocumentation)
operationId(?string)
parameters(ParameterContract ...)
requestBody(?RequestBodyContract)
responses(Responses|ResponseContract ...), addResponses(ResponseContract ...)Keyed by status code
callbacks(CallbackContract ...)
deprecated(?bool = true)
security(SecurityRequirement ...)Without argument: [], no authentication
servers(Server ...)

Responses, Callback

ObjectMethods
Responsesdefault(?ResponseContract), responses(ResponseContract ...); rarely needed, Operation::responses() builds it
Callback::create('onPaid')pathItems(PathItemContract ...), each keyed by a runtime expression; Callback::ref($ref, $objectId)

Parameters and headers

Parameter

Shortcuts: Parameter::path($name) (sets required: true), query($name), header($name), cookie($name), querystring($name) 3.2. The second argument is the objectId, for Components::parameters(). Parameter::ref('Page') refers to #/components/parameters/Page.

MethodNotes
name(?string), in(ParameterLocation|string|null)Set by the shortcuts
description(?string)
required(?bool = true), deprecated(?bool = true), allowEmptyValue(?bool = true)
style(ParameterStyle|string|null), explode(?bool = true), allowReserved(?bool = true)
schema(?SchemaContract)Or content
content(MediaTypeContract ...)One media type
example(mixed), examples(ExampleContract ...)Exclusive

Header::create('X-Rate-Limit'), Header::ref($ref, $objectId): description(), required(), deprecated(), style(), explode(), schema(), example(), examples(), content(), with the types of Parameter.

Bodies and content

RequestBody

RequestBody::create(), RequestBody::ref($ref, $objectId): description(?string), content(MediaTypeContract ...) (required), required(?bool = true).

MediaType

Shortcuts: MediaType::json(), xml(), formUrlEncoded(), multipart(), MediaType::of('text/csv'). MediaType::ref('BookJson', 'application/json') 3.2.

MethodNotes
schema(?SchemaContract)
itemSchema(?SchemaContract)3.2 each item of a stream
description(?string)3.2
example(mixed), examples(ExampleContract ...)Exclusive
encoding(Encoding ...)objectId = property name
prefixEncoding(Encoding ...), itemEncoding(?Encoding)3.2; exclusive with encoding

Encoding

Encoding::create('photo'): contentType(?string), headers(HeaderContract ...), style(), explode(), allowReserved(), and encoding(), prefixEncoding(), itemEncoding() 3.2.

Example

Example::create('admin'), Example::ref($ref, $objectId): summary(?string), description(?string), value(mixed), externalValue(?string), dataValue(mixed) 3.2, serializedValue(?string) 3.2. value excludes the three others; serializedValue excludes externalValue.

Responses

Response

Shortcuts, with the reason phrase as description: ok() 200, created() 201, accepted() 202, noContent() 204, movedPermanently() 301, found() 302, notModified() 304, badRequest() 400, unauthorized() 401, forbidden() 403, notFound() 404, methodNotAllowed() 405, conflict() 409, unprocessableEntity() 422, tooManyRequests() 429, internalServerError() 500, serviceUnavailable() 503. Others: Response::status(418), Response::status('4XX'), Response::create('default'). Response::ref('NotFound').

MethodNotes
description(?string)Written as "" when missing
summary(?string)3.2
headers(HeaderContract ...)
content(MediaTypeContract ...)
links(LinkContract ...)

Link::create('GetUser'), Link::ref($ref, $objectId): operationRef(?string) or operationId(?string) (exclusive), parameters(array<string, mixed>), requestBody(mixed), description(?string), server(?Server).

Schemas

Schema

Shortcuts: Schema::string(), integer(), number(), boolean(), array(), object(), null(); create() has no type. Schema::ref('User', 'owner') is a Schema.

GroupMethods
Typetype(SchemaType|string ...), nullable(?bool = true), format(?string)
Metadatatitle(), description(), default(mixed), example(mixed), examples(mixed ...), deprecated(), readOnly(), writeOnly(), externalDocs(), xml(?Xml), comment() 3.1+
Valuesenum(mixed ...), const(mixed)
Numbersminimum(), maximum(), exclusiveMinimum(), exclusiveMaximum(), multipleOf()
StringsminLength(), maxLength(), pattern(), contentEncoding(), contentMediaType(), contentSchema() 3.1+
Arraysitems(), minItems(), maxItems(), uniqueItems(); 3.1+: prefixItems(), contains(), minContains(), maxContains(), unevaluatedItems()
Objectsproperties(), required(string ...), additionalProperties(), minProperties(), maxProperties(); 3.1+: patternProperties(), propertyNames(), unevaluatedProperties(), dependentRequired(array), dependentSchemas()
CompositionallOf(), anyOf(), oneOf(), not(), discriminator(?Discriminator); 3.1+: if(), then(), else()
JSON Schema core3.1+: schema() ($schema), id() ($id), anchor(), dynamicAnchor(), dynamicRef(), defs() ($defs)

Discriminator, Xml

ObjectMethods
DiscriminatorpropertyName(?string) (required), mapping(array<string, string>), defaultMapping(?string) 3.2
Xmlname(), namespace(), prefix(), attribute(?bool = true), wrapped(?bool = true), nodeType(XmlNodeType|string|null) 3.2 (exclusive with attribute and wrapped)

Components and references

Components

Every section is keyed by the objectId of its entries: schemas(), responses(), parameters(), examples(), requestBodies(), headers(), securitySchemes(), links(), callbacks(), pathItems() 3.1+, mediaTypes() 3.2.

Reference

MethodNotes
static to(string $ref, ?string $objectId = null)Any reference
static for(SpecObject $component)Reference to a component object
ref(?string)
summary(?string), description(?string)3.1+

Security

SecurityScheme

Shortcuts: SecurityScheme::apiKey('key'), http('bearer'), oauth2('oauth'), openIdConnect('oidc'), mutualTLS('mtls') 3.1+; the argument is the scheme name. SecurityScheme::ref($ref, $objectId).

MethodUsed by
type(SecuritySchemeType|string|null)all
description(?string)all
name(?string), in(ApiKeyLocation|string|null)apiKey
scheme(?string), bearerFormat(?string)http
flows(?OAuthFlows)oauth2
oauth2MetadataUrl(?string)oauth2 3.2
openIdConnectUrl(?string)openIdConnect
deprecated(?bool = true)3.2

OAuthFlows, OAuthFlow, SecurityRequirement

ObjectMethods
OAuthFlowsimplicit(), password(), clientCredentials(), authorizationCode(), deviceAuthorization() 3.2, each ?OAuthFlow
OAuthFlowauthorizationUrl(), tokenUrl(), refreshUrl(), deviceAuthorizationUrl() 3.2, scopes(array<string, string>)
SecurityRequirementschemes(array<string, list<string>>): scheme name to required scopes; empty: optional authentication