marshmallow-code / marshmallow-code/apispec

Load operations from reStructedText

Open
#640 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
1.2k
Forks
202
Avg merge
3h 38m
Merged PRs (30d)
3

Description

Hi,

I'm working on a generating an operations dictionary from plain reStructuredText. This allow to get rid of the YAML an only use a plain doctstring to generate the OpenAPI structure.

The principle is as following:

def post_foo(self):
    """Add foo into the application.


    :body content application/vnd.api+json: Foo
    :body description: The foo to be added.
    :body required: Yes

    :deprecated: No

    :docs: A documentation for foo.
    :docs url: https://docs.example.com/api/v1/foo

    :id: foo

    :parameter test: A test parameter.
    :parameter test allow-empty: No
    :parameter test deprecated: No
    :parameter test explode: No
    :parameter test in: Query
    :parameter test required: Yes
    :parameter test style: Deep Object

    :response Ok content application/json: Foo
    :response Ok: The foo added to the application.

    """
    [...]

This cover so far most of the requirements for an Operations object and is fully functional on my side.

Note that in my current implementation, I take an extra function to lookup the HTTP code matching the provided textual representation (i.e Ok => 200).

The result from the above example is the following:

"/v1/foo": {
    "post": {
        "operationId": "foo",
        "requestBody": {
            "content": {
                "application/vnd.api+json": {
                    "schema": {
                        "$ref": "#/components/schemas/Foo"
                    }
                }
            },
            "description": "The foo to be added.",
            "required": true
        },
        "externalDocs": {
            "description": "An external documentation.",
            "url": "http://docs.example.com/api/v1/foo"
        },
        "responses": {
            "200": {
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/Foo"
                        }
                    }
                },
                "description": "The foo added to the application."
            }
        },
        "parameters": [
            {
                "name": "test",
                "description": "A test parameter.",
                "allowEmptyValue": false,
                "deprecated": false,
                "explode": false,
                "in": "query",
                "required": true,
                "style": "deepObject"
            }
        ]
    }
}

Now I'm working on translating reStructuredText to CommonMark where applicable.

Is this something you would be interested in having in apispec? I can work on a pull request.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files, tests, or entry points are named. Start with the issue's reStructuredText operation example and compare it with apispec's current OpenAPI generation and YAML handling; done means generating the shown Operations structure from a plain docstring, including HTTP status lookup and CommonMark translation where applicable.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, python
Domain
api, documentation
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.