项目作者: swaggest

项目描述 :
OpenAPI/Swagger client generator for PHP and Go
高级语言: PHP
项目地址: git://github.com/swaggest/swac.git
创建时间: 2019-10-17T00:32:59Z
项目社区:https://github.com/swaggest/swac

开源协议:MIT License

下载


OpenAPI 3.0 / Swagger 2.0 compiler

A tool to render API spec as code.

Build Status
codecov
Image Size
Code lines
Comments

Installation

Phar

Download swac from releases page.

Docker

  1. docker run --rm swaggest/swac swac --help
  1. v0.1.28 swac
  2. OpenAPI/Swagger compiler, https://github.com/swaggest/swac
  3. Usage:
  4. swac <action>
  5. action Action name
  6. Allowed values: php-guzzle-client, go-client, js-client, markdown
  7. ...

Example

  1. mkdir petstore && cd petstore
  2. docker run -v $(pwd):/code -u 1000:1000 swaggest/swac swac php-guzzle-client https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/json/petstore.json --namespace MyApp\\Petstore

Schema can be passed by STDIN using - as file path.

  1. cat ./openapi.json | docker run -i --rm swaggest/swac swac markdown -

Composer

Install PHP Composer

  1. composer global require swaggest/swac

Usage

PHP Client

  1. swac php-guzzle-client --help
  1. v0.1.0 swac php-guzzle-client
  2. OpenAPI/Swagger compiler, https://github.com/swaggest/swac
  3. Usage:
  4. swac php-guzzle-client <schemaPath> --namespace <namespace>
  5. schemaPath Path/URL to OpenAPI/Swagger schema
  6. Options:
  7. --operations <operations> Operations filter in form of comma-separated list of method/path, default empty
  8. --project-path <projectPath> Path to project root, default ./
  9. --namespace <namespace> Project namespace

The generated client depends on swaggest/rest-client,
guzzlehttp/guzzle 6, and swaggest/json-schema.

Examples.

Go Client

  1. swac go-client --help
  1. v0.1.14 swac go-client
  2. OpenAPI/Swagger compiler, https://github.com/swaggest/swac
  3. Usage:
  4. swac go-client <schemaPath>
  5. schemaPath Path/URL to OpenAPI/Swagger schema
  6. Options:
  7. --operations <operations> Operations filter in form of comma-separated list of method/path, default empty
  8. --out <out> Path to output package, default ./client
  9. --pkg-name <pkgName> Output package name, default "client"
  10. --skip-default-additional-properties Do not add field property for undefined `additionalProperties`
  11. --skip-do-not-edit Skip adding "DO NOT EDIT" comments
  12. --add-request-tags Add field tags with name and location to request structure properties, e.g. 'ID int `query:"id"`'
  13. --show-const-properties Show properties with constant values, hidden by default
  14. --keep-parent-in-property-names Keep parent prefix in property name, removed by default
  15. --ignore-nullable Add `omitempty` to nullable properties, removed by default
  16. --ignore-xgo-type Ignore `x-go-type` in schema to skip generation
  17. --with-zero-values Use pointer types to avoid zero value ambiguity
  18. --fluent-setters Add fluent setters to struct fields
  19. --ignore-required Ignore if property is required when deciding on pointer type or omitempty
  20. --renames <renames...> Map of exported symbol renames, example From:To
  21. --with-tests Generate (un)marshaling tests for entities (experimental feature)
  22. --require-xgenerate Generate properties with `x-generate: true` only
  23. --validate-required Generate validation code to check required properties during unmarshal

Examples.

The generated client is a single package without external dependencies.

JavaScript Client

  1. swac js-client --help
  1. v0.1.21 swac js-client
  2. OpenAPI/Swagger compiler, https://github.com/swaggest/swac
  3. Usage:
  4. swac js-client <schema>
  5. schema Path/URL to OpenAPI/Swagger schema
  6. Options:
  7. --operations <operations> Operations filter in form of comma-separated list of method/path, default empty
  8. --ignore-operation-id Ignore operationId and always name operations using method and path
  9. --client-name <clientName> Name of generated client class, default APIClient
  10. --types-prefix <typesPrefix> Prefix generated jsdoc class names
  11. --out <out> Path to output files, default ./client
  12. --patches <patches...> JSON patches to apply to schema file before processing, merge patches are also supported

Examples.

  1. swac js-client openapi.json --out ./ --client-name Backend --types-prefix xh

The generated client is a ES5 class using XMLHttpRequest and jsdoc type definitions without external dependencies
suitable for direct usage in browsers.

Markdown

  1. swac markdown --help
  1. v0.1.24 swac markdown
  2. OpenAPI/Swagger compiler, https://github.com/swaggest/swac
  3. Usage:
  4. swac markdown <schema>
  5. schema Path/URL to OpenAPI/Swagger schema
  6. Options:
  7. --operations <operations> Operations filter in form of comma-separated list of method/path, default empty
  8. --ignore-operation-id Ignore operationId and always name operations using method and path
  9. --client-name <clientName> Name of generated client class, default APIClient
  10. --add-schema-url <addSchemaUrl> Add schema link to the document
  11. --types-prefix <typesPrefix> Prefix generated type names
  12. --out <out> Path to output files, default ./client
  13. --patches <patches...> JSON patches to apply to schema file before processing, merge patches are also supported

Examples.

  1. swac markdown openapi.json --out ./API-Docs.md --types-prefix xh