Giter VIP home page Giter VIP logo

entrepreneur-interet-general / open_api_schemas_to_markdown Goto Github PK

View Code? Open in Web Editor NEW
11.0 14.0 1.0 33 KB

Generate Markdown documentation from OpenAPI 3 Components Schemas

Home Page: https://pypi.org/project/open-api-schemas-to-markdown/

License: MIT License

Python 100.00%
entrepreneur-interet-general eig-2018 predisauvetage openapi3 openapi-documentation markdown github-flavored-markdown

open_api_schemas_to_markdown's Introduction

Software License CircleCI PyPI

OpenAPI Components Schemas to Markdown

The goal of this package is to generate Github Flavored Markdown documentation of Components Schemas from the OpenAPI 3 specification.

Say you've got a YAML file:

openapi: "3.0.0"
info:
  version: "0"
  title: Demo
paths:
  /demo:
    get:
      summary: Demo
      responses:
        '200':
          description: OK
components:
  schemas:
    ResultatHumain:
      properties:
        operation_id:
          type: integer
          format: int64
          description: Le numéro unique de l'opération
          example: 1119920371
        categorie_personne:
          type: string
          description: Indique la catégorie de personne impliquée dans le bilan humain
          example: Pêcheur français
        resultat_humain:
          type: string
          description: Description du bilan humain
          example: Personne secourue
        nombre:
          type: number
          format: int32
          minimum: 0
          description: Nombre de personnes impliquées dans ce bilan
          example: 3
        dont_nombre_blesse:
          type: number
          format: int32
          minimum: 0
          description: Indique le nombre de personnes blessées dans le bilan
          example: 1

The package will produce a Markdown file from the YAML specification file with the following content:

## ResultatHumain
|Field|Type|Description|Example|Properties|
|---|---|---|---|---|
|operation_id|integer($int64)|Le numéro unique de l'opération|1119920371||
|categorie_personne|string|Indique la catégorie de personne impliquée dans le bilan humain|Pêcheur français||
|resultat_humain|string|Description du bilan humain|Personne secourue||
|nombre|number($int32)|Nombre de personnes impliquées dans ce bilan|3|minimum: 0|
|dont_nombre_blesse|number($int32)|Indique le nombre de personnes blessées dans le bilan|1|minimum: 0|

And if you render it:

ResultatHumain

Field Type Description Example Properties
operation_id integer($int64) Le numéro unique de l'opération 1119920371
categorie_personne string Indique la catégorie de personne impliquée dans le bilan humain Pêcheur français
resultat_humain string Description du bilan humain Personne secourue
nombre number($int32) Nombre de personnes impliquées dans ce bilan 3 minimum: 0
dont_nombre_blesse number($int32) Indique le nombre de personnes blessées dans le bilan 1 minimum: 0

Installation

pip install open-api-schemas-to-markdown

Usage

The package provides a command line tool.

$ oa-to-md -h
usage: oa-to-md [-h] input_filepath output_filepath [locale]

positional arguments:
  input_filepath   The OpenAPI 3 YAML filepath
  output_filepath  The desired output filepath of the Markdown file
  locale           Locale to use when generating the Markdown file. Available:
                   en, fr

optional arguments:
  -h, --help       show this help message and exit

Example:

oa-to-md open_api.yml documentation.md

Notice

This software is available under the MIT license and was developed as part of the Entrepreneur d'Intérêt Général program by the French government.

Projet développé dans le cadre du programme « Entrepreneur d’intérêt général ».

open_api_schemas_to_markdown's People

Contributors

antoineaugusti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

ma-serra

open_api_schemas_to_markdown's Issues

Dose not seam to work with $ref in schema

Dose not seam to work with $ref in schema, added a print to the statement and seeing the bellow:

OrderedDict([('type', 'string')]) OrderedDict([('type', 'int')]) OrderedDict([('type', 'integer'), ('format', 'int')]) OrderedDict([('type', 'string')]) OrderedDict([('type', 'string')]) OrderedDict([('type', 'integer'), ('format', 'int')]) OrderedDict([('type', 'string')]) OrderedDict([('type', 'string')]) OrderedDict([('type', 'boolean')]) OrderedDict([('$ref', '#/components/schemas/Organisation')]) Traceback (most recent call last): File "/Users/neil.baillie/.pyenv/versions/3.7.5rc1/bin/oa-to-md", line 27, in <module> converter.convert() File "/Users/neil.baillie/.pyenv/versions/3.7.5rc1/lib/python3.7/site-packages/open_api_schemas_to_markdown/converter.py", line 29, in convert ObjectFormatter(object_name, values, self.locale).format() File "/Users/neil.baillie/.pyenv/versions/3.7.5rc1/lib/python3.7/site-packages/open_api_schemas_to_markdown/converter.py", line 56, in format type=self.type(values), File "/Users/neil.baillie/.pyenv/versions/3.7.5rc1/lib/python3.7/site-packages/open_api_schemas_to_markdown/converter.py", line 98, in type return values['type'] KeyError: 'type

Doesn't handle lists

components:
  schemas:
    Operation:
      properties:
        operation_id:
          type: integer
          format: int64
          description: Le numéro unique de l'opération
          example: 1119920371
        pourquoi_alerte:
          type: string
          enum: [SAR, MAS, DIV, SUR]
          description: >
            La catégorie du type d'intervention.
              - SAR (search and rescue) : vie humaine en danger.
              - MAS (maritime assistance service) : assistance aux navires
              - SUR : sûreté des navires
              - DIV : autres cas
          example: SAR

Will not produce a valid Markdown file

not working

Getting this error :

Traceback (most recent call last):
  File "/usr/local/bin/oa-to-md", line 27, in <module>
    converter.convert()
  File "/usr/local/lib/python3.9/site-packages/open_api_schemas_to_markdown/converter.py", line 29, in convert
    ObjectFormatter(object_name, values, self.locale).format()
  File "/usr/local/lib/python3.9/site-packages/open_api_schemas_to_markdown/converter.py", line 56, in format
    type=self.type(values),
  File "/usr/local/lib/python3.9/site-packages/open_api_schemas_to_markdown/converter.py", line 97, in type
    return values['type']
KeyError: 'type'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.