You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: CONTRIBUTING.md
+2
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@ Thank you for considering contributing to OpenAPIKit!
2
2
3
3
Take a look at the [Code of Conduct](https://github.com/mattpolzin/OpenAPIKit/blob/master/CODE_OF_CONDUCT.md) and note the [MIT license](https://github.com/mattpolzin/OpenAPIKit/blob/master/LICENSE.txt) associated with this project.
4
4
5
+
If you are preparing a change for the current release of OpenAPIKit (major version 3), branch off of the `main` branch of this repositroy. If you are preparing a fix for version 2 of OpenAPIKit, branch off of the `release/2_x` branch of this repository. If you are preparing a change for the next major release of OpenAPIKit (major version 4), branch off of the `release/4_0` branch of this repository.
6
+
5
7
Please do the following in the course of preparing a branch and pull request for this project.
6
8
7
9
- Create an issue motivating the changes you've made if one does not already exist. If you are unsure of how to adress an issue, seek out converstation on the issue before committing to a strategy.
Copy file name to clipboardexpand all lines: README.md
+11-8
Original file line number
Diff line number
Diff line change
@@ -100,7 +100,7 @@ do {
100
100
101
101
You can encode a JSON OpenAPI document (i.e. using the `JSONEncoder` from the **Foundation** library) or a YAML OpenAPI document (i.e. using the `YAMLEncoder` from the [**Yams**](https://github.com/jpsim/Yams) library) with the following code:
102
102
```swift
103
-
let openAPIDoc =...
103
+
let openAPIDoc: OpenAPI.Document=...
104
104
let encoder =...// JSONEncoder() or YAMLEncoder()
105
105
let encodedOpenAPIDoc =try encoder.encode(openAPIDoc)
106
106
```
@@ -111,7 +111,7 @@ Thanks to Swift's type system, the vast majority of the OpenAPI Specification is
111
111
That being said, there are a small number of additional checks that you can perform to really put any concerns to bed.
112
112
113
113
```swift
114
-
let openAPIDoc =...
114
+
let openAPIDoc: OpenAPI.Document=...
115
115
// perform additional validations on the document:
116
116
try openAPIDoc.validate()
117
117
```
@@ -160,7 +160,7 @@ If retaining order is important for your use-case, I recommend the [**Yams**](ht
160
160
The Foundation JSON encoding and decoding will be the most stable and battle-tested option with Yams as a pretty well established and stable option as well. FineJSON is lesser used (to my knowledge) but I have had success with it in the past.
161
161
162
162
### OpenAPI Document structure
163
-
The types used by this library largely mirror the object definitions found in the [OpenAPI specification](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md) version 3.0.3. The [Project Status](#project-status) lists each object defined by the spec and the name of the respective type in this library.
163
+
The types used by this library largely mirror the object definitions found in the OpenAPI specification[version 3.1.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md)(`OpenAPIKit` module) and [version 3.0.3](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md) (`OpenAPIKit30` module). The [Project Status](#project-status) lists each object defined by the spec and the name of the respective type in this library. The project status page currently focuses on OpenAPI 3.1.x but for the purposes of determining what things are named and what is supported you can mostly infer the status of the OpenAPI 3.0.x support as well.
164
164
165
165
#### Document Root
166
166
At the root there is an `OpenAPI.Document`. In addition to some information that applies to the entire API, the document contains `OpenAPI.Components` (essentially a dictionary of reusable components that can be referenced with `JSONReferences` and `OpenAPI.References`) and an `OpenAPI.PathItem.Map` (a dictionary of routes your API defines).
@@ -183,7 +183,7 @@ A schema can be made **optional** (i.e. it can be omitted) with `JSONSchema.inte
183
183
184
184
A schema can be made **nullable** with `JSONSchema.number(nullable: true)` or an existing schema can be asked for a `nullableSchemaObject()`.
185
185
186
-
Nullability highlights an important decision OpenAPIKit makes. The JSON Schema specification that dictates how OpenAPI v3.1 documents _encode_ nullability states that a nullable property is encoded as having the `null` type in addition to whatever other type(s) it has. So in OpenAPIKit you set `nullability` as a property of a schema, but when encoded/decoded it will represent the inclusion of absence of `null` in the list of `type`s of the schema.
186
+
Nullability highlights an important decision OpenAPIKit makes. The JSON Schema specification that dictates how OpenAPI v3.1 documents _encode_ nullability states that a nullable property is encoded as having the `null` type in addition to whatever other type(s) it has. So in OpenAPIKit you set `nullability` as a property of a schema, but when encoded/decoded it will represent the inclusion of absence of `null` in the list of `type`s of the schema. If you are using the `OpenAPIKit30` module then nullability is encoded as a `nullable` property per the OpenAPI 3.0.x specification.
187
187
188
188
Some types of schemas can be further specialized with a **format**. For example, `JSONSchema.number(format: .double)` or `JSONSchema.string(format: .dateTime)`.
189
189
@@ -311,7 +311,7 @@ Unlike what happens when you lookup an individual component using the `lookup()`
311
311
312
312
Anywhere that a type would have had either a reference or a component, the dereferenced variety will simply have the component. For example, `PathItem` has an array of parameters, each of which is `Either<OpenAPI.Reference<Parameter>, Parameter>` whereas a `DereferencedPathItem` has an array of `DereferencedParameter`s. The dereferenced variant of each type exposes all the same properties and you can get at the underlying `OpenAPI` type via an `underlying{TypeName}` property. This can make for a much more convenient way to traverse a document because you don't need to check for or look up references anywhere the OpenAPI Specification allows them.
313
313
314
-
For all dereferenced types except for `JSONSchema`, dereferencing will store a new vendor extension on the dereferenced value to keep track of the Component Object name the value used to be referenced at. This vendor extension is a string value with the `x-component-name` key.
314
+
For all dereferenced types, dereferencing will store a new vendor extension on the dereferenced value to keep track of the Component Object name the value used to be referenced at. This vendor extension is a string value with the `x-component-name` key.
315
315
316
316
You can take things a step further and resolve the document. Calling `resolved()` on a `DereferencedDocument` will produce a canonical form of an `OpenAPI.Document`. The `ResolvedRoute`s and `ResolvedEndpoint`s that the `ResolvedDocument` exposes collect all relevant information from the whole document into themselves. For example, a `ResolvedEndpoint` knows what servers it can be used on, what path it is located at, and which parameters it supports (even if some of those parameters were defined in an `OpenAPI.Operation` and others were defined in the containing `OpenAPI.PathItem`).
317
317
@@ -359,16 +359,19 @@ Following is a short list of integrations that might be immediately useful or ju
359
359
360
360
If you have a library you would like to propose for this section, please create a pull request and explain a bit about your project.
361
361
362
-
### Declarative OpenAPI Documents
363
-
364
-
The [**Swift Package Registry API Docs**](https://github.com/mattt/swift-package-registry-oas) define the OpenAPI documentation for the Swift Package Registry standard using declarative Swift code and OpenAPIKit. This project also provides a useful example of producing a user-friendly ReDoc web interface to the OpenAPI documentation after encoding it as YAML.
362
+
### Generating Swift
363
+
The [**swift-openapi-generator**](https://github.com/apple/swift-openapi-generator) uses OpenAPIKit under the hood and generates Swift code for interfacing with APIs that have OpenAPI descriptions.
365
364
366
365
### Generating OpenAPI Documents
367
366
368
367
[**VaporOpenAPI**](https://github.com/mattpolzin/VaporOpenAPI) / [VaporOpenAPIExample](https://github.com/mattpolzin/VaporOpenAPIExample) provide an example of generating OpenAPI from a Vapor application's routes.
369
368
370
369
[**JSONAPI+OpenAPI**](https://github.com/mattpolzin/jsonapi-openapi) is a library that generates OpenAPI schemas from JSON:API types. The library has some rudimentary and experimental support for going the other direction and generating Swift types that represent JSON:API resources described by OpenAPI documentation.
371
370
371
+
### Declarative OpenAPI Documents
372
+
373
+
The [**Swift Package Registry API Docs**](https://github.com/mattt/swift-package-registry-oas) define the OpenAPI documentation for the Swift Package Registry standard using declarative Swift code and OpenAPIKit. This project also provides a useful example of producing a user-friendly ReDoc web interface to the OpenAPI documentation after encoding it as YAML.
374
+
372
375
### Semantic Diffing of OpenAPI Documents
373
376
374
377
[**OpenAPIDiff**](https://github.com/mattpolzin/OpenAPIDiff) is a library and a CLI that implements semantic diffing; that is, rather than just comparing two OpenAPI documents line-by-line for textual differences, it parses the documents and describes the differences in the two OpenAPI ASTs.
Copy file name to clipboardexpand all lines: documentation/schema_object.md
+6-4
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
2
2
## Schema Object
3
-
In OpenAPIKit, the Schema Object from the OpenAPI Specification is represented by the `JSONSchema` type. Indeed, OpenAPIKit borrows most of the details of its Schema Object from the JSON Schema specification.
3
+
In OpenAPIKit, the Schema Object from the OpenAPI Specification is represented by the `JSONSchema` type. Indeed, OpenAPI 3.1.x fully supports the JSON Schema specification, though OpenAPIKit does not (yet) have 100% complete JSON Schema specification support.
4
4
5
5
A `JSONSchema` can be:
6
6
1. Any of the fundamental types (`boolean`, `number`, `integer`, `string`, and in OpenAPI v3.1 `null`).
@@ -10,13 +10,15 @@ A `JSONSchema` can be:
10
10
5.`not` another schema.
11
11
6.`fragment` (which means the type of schema is not specified).
12
12
13
-
The fundamental schema types and arrays and objects all share a common set of properties (accessible from their `coreContext`) and each (except for boolean) also has some properties that only apply to that one type (accessible from properties named after the type like `objectContext`, `arrayContext`, `integerContext`, etc.).
13
+
The fundamental schema types and arrays and objects all share a common set of properties (accessible from their `coreContext`) and each (except for `boolean` and `null`) also has some properties that only apply to that one type (accessible from properties named after the type like `objectContext`, `arrayContext`, `integerContext`, etc.).
14
14
15
-
You can also extract these properties with pattern matching on a `JSONSchema`.
15
+
You can also extract these properties with pattern matching on a `JSONSchema`'s `value`.
16
+
17
+
**IMPORTANT**: `JSONSchema` is a struct with static convenience functions on it; when pattern matching, always pattern match on the `value` property of the `JSONSchema` type.
0 commit comments