Swagger series software introduction

Swagger – editor is introduced

Swagger-editor mainly uses YAML syntax to write API documents. The written documents can generate JSON files and YAML files for swagger-Generator generation code, and swagger-UI online document generation and testing

Swagger-editor installation method

Official examples are more complex, introduced various installation methods, read for a long time to clarify. Installation method 1:

git clone https://github.com/swagger-api/swagger-editor.git
cd swagger-editor
npm install
npm start
Copy the code

Do not know why NPM install obtain data flash, suspected that the wall problem installation method 2: download the official release package download address, and then run the following command

npm install -g http-server
http-server swagger-editor
Copy the code

To run http-server, go to swagger-editor directory, otherwise you will report icon not found error.

Swagger – the generator is introduced

Swagger-generator Is used to generate json files and YAML files generated by swagger-Editor according to the specified template file. You can refer to the bin script for a complete command format.

Installation method:

Direct BREW installation, source code to download Java dependency, compilation more trouble

brew install swagger-codegen
Copy the code

The script content

#! /bin/sh
cd /Users/mac/Documents/MyWork/openSourceProject/swagger-codegen-master/mysource
swagger-codegen generate -t swift -i myyaml.yaml -l swift -o default
cd/Users/mac/Documents/MyWork/openSourceProject/swagger-codegen-master/mysource/default/SwaggerClient/Classes/Swaggers/Mod els find * | xargs sed -i' ' 's/Int32/Int/g'
find * | xargs sed -i ' ' 's/StringValue/stringValue/g'
find * | xargs sed -i ' ' 's/IntValue/intValue/g'
Copy the code

swagger-codegen generate -t swift -i myyaml.yaml -l swift -o default

  • -t swift presentation template folder, original position in the modules/swagger codegen/SRC/main/resources/swift, I am a single copy
  • -i myyaml. Yaml indicates the input YAMl or JSON file
  • -l swift The language is swift
  • -o default Indicates that the last three commands of the output folder are replaced by scripts because some alternative templates cannot be completed
  • Find * finds all files in the current folder, and xargs passes arguments
  • Sed -i “‘s/Int32/Int/g’ sed -i” ‘s/Int32/Int/g