Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to openapi-core 0.17 #206

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Validate [Pyramid](https://trypyramid.com) views against an [OpenAPI 3.0](https://swagger.io/specification/) document
## Validate [Pyramid](https://trypyramid.com) views against an [OpenAPI 3.1](https://swagger.io/specification/) document

<p align="center">
<img height="200" src="https://github.com/Pylons/pyramid_openapi3/blob/main/header.jpg?raw=true" />
Expand Down Expand Up @@ -37,7 +37,7 @@ The reason this package exists is to give you peace of mind when providing a RES

- Your **API documentation is never out-of-date**, since it is generated out of the API document that you write.
- The documentation comes with **_try-it-out_ examples** for every endpoint in your API. You don't have to provide (and maintain) `curl` commands to showcase how your API works. Users can try it themselves, right in their browsers.
- Your **API document is always valid**, since your Pyramid app won't even start if the document does not comply with the OpenAPI 3.0 specification.
- Your **API document is always valid**, since your Pyramid app won't even start if the document does not comply with the OpenAPI 3.1 specification.
- Automatic request **payload validation and sanitization**. Your views do not require any code for validation and input sanitation. Your view code only deals with business logic. Tons of tests never need to be written since every request, and its payload, is validated against your API document before it reaches your view code.
- Your API **responses always match your API document**. Every response from your view is validated against your document and a `500 Internal Server Error` is returned if the response does not exactly match what your document says the output of a certain API endpoint should be. This decreases the effects of [Hyrum's Law](https://www.hyrumslaw.com).
- **A single source of truth**. Because of the checks outlined above, you can be sure that whatever your API document says is in fact what is going on in reality. You have a single source of truth to consult when asking an API related question, such as "Remind me again, which fields are returned by the endpoint `/user/info`?".
Expand All @@ -49,7 +49,7 @@ The reason this package exists is to give you peace of mind when providing a RES

## Features

- Validates your API document (for example, `openapi.yaml` or `openapi.json`) against the OpenAPI 3.0 specification using the [openapi-spec-validator](https://github.com/p1c2u/openapi-spec-validator).
- Validates your API document (for example, `openapi.yaml` or `openapi.json`) against the OpenAPI 3.1 specification using the [openapi-spec-validator](https://github.com/p1c2u/openapi-spec-validator).
- Generates and serves the [Swagger try-it-out documentation](https://swagger.io/tools/swagger-ui/) for your API.
- Validates incoming requests *and* outgoing responses against your API document using [openapi-core](https://github.com/p1c2u/openapi-core).

Expand Down Expand Up @@ -80,7 +80,7 @@ For responses, if the payload does not match the API document, an exception is r

### Relative File References in Spec

A feature introduced in OpenAPI3 is the ability to use `$ref` links to external files (https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#referenceObject).
A feature introduced in OpenAPI3 is the ability to use `$ref` links to external files (https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#reference-object).

To use this, you must ensure that you have all of your spec files in a given directory (ensure that you do not have any code in this directory as all the files in it are exposed as static files), then **replace** the `pyramid_openapi3_spec` call that you did in [Getting Started](#getting-started) with the following:

Expand Down
2 changes: 1 addition & 1 deletion examples/singlefile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ z

* More information about the library providing the integration between OpenAPI specs and Pyramid, more advanced features and design defence, is available in the main [README](https://github.com/Pylons/pyramid_openapi3) file.

* More validators for fields are listed in the [OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#properties) document. You can use Regex as well.
* More validators for fields are listed in the [OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#properties) document. You can use Regex as well.

* For an idea of a fully-fledged production OpenApi specification, check out [WooCart's OpenAPI docs](https://app.woocart.com/api/v1/).
4 changes: 2 additions & 2 deletions examples/singlefile/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# example we want everything in a single file. Other examples have it nicely
# separated.
OPENAPI_DOCUMENT = b"""
openapi: "3.0.0"
openapi: "3.1.0"
info:
version: "1.0.0"
title: Hello API
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_name_missing(self):
We don't have to write (and test!) any validation code in our view!
"""
res = self.testapp.get("/hello", status=400)
self.assertIn("Missing required parameter: name", res.text)
self.assertIn("Missing required query parameter: name", res.text)

def test_name_too_short(self):
"""A name that is too short is picked up by openapi-core validation.
Expand Down
2 changes: 1 addition & 1 deletion examples/splitfile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ All of these examples are covered with tests that you can run with `$ python -m

* More information about the library providing the integration between OpenAPI specs and Pyramid, more advanced features and design defence, is available in the main [README](https://github.com/Pylons/pyramid_openapi3) file.

* More validators for fields are listed in the [OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#properties) document. You can use Regex as well.
* More validators for fields are listed in the [OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#properties) document. You can use Regex as well.

* For an idea of a fully-fledged production OpenApi specification, check out [WooCart's OpenAPI docs](https://app.woocart.com/api/v1/).
44 changes: 33 additions & 11 deletions examples/splitfile/spec/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
openapi: "3.0.0"
openapi: "3.1.0"

info:
version: "1.0.0"
title: A simple Todo app API

paths:
/:
$ref: "paths.yaml#/todos"
get:
summary: List of my TODO items
responses:
'200':
description: A list of my TODO items
content:
application/json:
schema:
type: array
items:
$ref: "schemas.yaml#/Item"

components:
schemas:
Item:
$ref: "schemas.yaml#/Item"
post:
summary: Create a TODO item
operationId: todo.create
requestBody:
required: true
description: Data for creating a new TODO item
content:
application/json:
schema:
$ref: schemas.yaml#/Item

Error:
$ref: "schemas.yaml#/Error"
responses:
'200':
description: Success message.
content:
application/json:
schema:
type: string

responses:
ValidationError:
$ref: "responses.yaml#/ValidationError"
'400':
$ref: responses.yaml#/ValidationError
'500':
$ref: responses.yaml#/ValidationError
36 changes: 0 additions & 36 deletions examples/splitfile/spec/paths.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion examples/todoapp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ All of these examples are covered with tests that you can run with `$ python -m

* More information about the library providing the integration between OpenAPI specs and Pyramid, more advanced features and design defence, is available in the main [README](https://github.com/Pylons/pyramid_openapi3) file.

* More validators for fields are listed in the [OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#properties) document. You can use Regex as well.
* More validators for fields are listed in the [OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#properties) document. You can use Regex as well.

* For an idea of a fully-fledged production OpenApi specification, check out [WooCart's OpenAPI docs](https://app.woocart.com/api/v1/).
2 changes: 1 addition & 1 deletion examples/todoapp/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
openapi: "3.0.0"
openapi: "3.1.0"

info:
version: "1.0.0"
Expand Down
Loading