
Security News
High Salaries No Longer Enough to Attract Top Cybersecurity Talent
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
@devexperts/swagger-codegen-ts
Advanced tools
fetch
, Axios
or any other libraryfp-ts
and io-ts
librariesThe examples below refer to the Pet Store OpenAPI 3.0 schema.
After running the codegen, interacting with a REST API may be as simple as this:
import { petController as createPetController } from "./src/generated/petstore.json/paths/PetController";
import { Pet } from "./src/generated/petstore.json/components/schemas/Pet";
// Creating a controller, see the "HTTP Clients" wiki page for more details
const petController = createPetController({ httpClient: fetchHttpClient });
// The returned object is guaranteed to be a valid `Pet`
const createdPet: Promise<Pet> = petController.addPet({
body: {
// The parameters are statically typed, IntelliSense works, too
name: "Spotty",
photoUrls: [],
},
});
More usage scenarios are supported - check the usage page for more detail.
Make sure the peer dependencies are installed, then install the codegen itself:
yarn add typescript fp-ts io-ts io-ts-types
yarn add -D @devexperts/swagger-codegen-ts
Create a console script that would invoke the generate
function, passing the options such as path to the schema file and the output directory.
See the Generators page for the API reference, and examples/generate for sample scripts.
In most cases, you might want to include the code generation step into the build and local launch scripts. Example:
/* package.json */
"scripts": {
+ "generate:api": "ts-node scripts/generate-api.ts",
- "start": "react-scripts start",
+ "start": "yarn generate:api && react-scripts start",
- "build": "react-scripts build"
+ "build": "yarn generate:api && react-scripts build"
}
Please read the Contributors Guide for more information.
FAQs
TS generator for swagger spec
The npm package @devexperts/swagger-codegen-ts receives a total of 5,762 weekly downloads. As such, @devexperts/swagger-codegen-ts popularity was classified as popular.
We found that @devexperts/swagger-codegen-ts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 11 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A survey of 500 cybersecurity pros reveals high pay isn't enough—lack of growth and flexibility is driving attrition and risking organizational security.
Product
Socket, the leader in open source security, is now available on Google Cloud Marketplace for simplified procurement and enhanced protection against supply chain attacks.
Security News
Corepack will be phased out from future Node.js releases following a TSC vote.