This repo is for Xfers' API documentation. Beta site for API documentation (https://xfers.github.io/oas-api-docs/)
This README contains information regarding the big picture of Xfers' approach to API documentation. To get the detailed information on how the parser or front end works refer to the dir README. Client facing interface check react-pages
directory. For information on the Parser
check ruby-parser
directory.
- Xfers have multiple products that currently require different documentation.
- Manually creating the documentation for each product is inefficient and problems of inconsistency will arise
- Any changes made to the endpoints that are used by multiple documentations require changes to be made manually to each documentation
To tackle the above problems, this repo aims to create a way of documentation at a higher level of abstraction. Any changes made to the documentation should only be made to 1 source to ensure efficiency and standardization.
Flow
- Any changes Xfers wants to make will be made to
/react-page/src/oas_spec/master-openapi.json
master-openapi.json
will contain all of Xfers endpoints (Singapore-specific and Indonesia-specific) and all of Xfers parameters
- Run
cd ruby-parser
in the root directory and executerake generate
in the command line. This will:
- read and parse the local
/react-page/src/oas_spec/master-openapi.json
- create 2
.json
files:Singapore.json
andIndonesia.json
(or merchant specific Documents). These files will be written to/react-page/src/oas_spec
- The json file will be generated in accordance to
/ruby-parser/config/oas.yml
, where you can state the endpoints you want in each documentation by stating it under thepaths
field (e.g."/user/activities"
and"/authorize*"
- The github pages that host our docuementation is built according to json files in the
/react-page/src/oas_spec/
folder. Once the json files have been written into the directory, the page will be updated.
- Ability to generate any number of customized documentation quickly by changing
ruby-parser/config/oas.yml
- Ability to define specific parameters for different sets of documentation by adding this fied
"x-custom-params"
. More info here - Ability to state custom parameter requires wrt to the country add this field
"x-custom-params-requirements"
- API docs analytics powered by Google Analytics(WIP)
- Changes to Client facing interface
- Refer to /reac-pages/README.md
- Changes to behavior and functionality of Parser
- Refer to /ruby-parser/README.md
- Changes to content of the docuementation rendered to the client see below
- Refer to /src/oas_spec/README.md for information on details on OAS
Optional Env setup(make your life easier)
- Download VS Code OpenAPI (Swagger) editor
- Download openapi-lint
- clone entire repo
cd react-page
npm install
Make changes to master-openapi.json
npm start
- open
http://localhost:3000/#/master
- make desired changes to
master-openapi.json
. When you save changeshttp://localhost:3000/#/master
will hot reload and you can review the changes you made - Once satisfied cd to
ruby-parser
and runrake generate
- View changes made to client facing interface on
http://localhost:3000
- Create PR and let PM/Engineer review
- Once approved run
npm run deploy
inreact-page
- Changes will be seen on
https://xfers.github.io/oas-api-docs/#/
Generate new documentation for a specific merchant
- open
/ruby-parser/config/oas.yml
- add a new object at the bottom of the yaml file following this format stated
- run
rake generate
inruby-parser
- open
/react-pages/src/pages/TemplateOas.js
- Make changes according to comment and save as new file(name of file: {doc-name}.js)
- open
/react-pages/src/App.js
and make changes according to the comment(make sure you do not delete the comments) - run
npm run
inreact-page
and check doc inhttp://localhost:3000/#/{doc-name}
- Once satisfied create PR and let PM/Engineer review
- Once approved run
npm run deploy
inreact-page
- Changes will be seen on
https://xfers.github.io/oas-api-docs/#/{doc-name}
Refer to PR Xfers#2 for front end changes Refer to Issue https://github.com/Xfers/Xfers/issues/11078 for the complete picture
Here are information that you cannot find anywhere on the interent. Read this to save your time googling it.
- To have path/query/requestBody parameters only present in certain document
- This code will only work if you add into
Parameter Object
andSchema Object
- Legend:
doc_nameX => the name of the document(as per config.yml)
"x-custom-params" : ["doc_name1","doc_name2"],
- To have certain parameters only required for certain document
- This code will only work if you add into
Shema Object
in requestBody - Legend:
doc_nameX => the name of the document(as per config.yml)
,paramX => the name of parameters you want to be required by only certain documents
Documentation here
- Tags that are for general information and have nothing to do with endpoints
- This code will only work if you add into
Tags Object
in"tags"
"x-traitTag" : true
- To add sample
curl or ...
http request
"x-code-samples": [{
"lang": "Shell_curl", //Lang of request
"source": "curl --location --request ..." //example of curl request
}],