Swagger CodeGen Https SSL Connectivity - swagger

I need to create swagger codegen client for java, javascript pointing to swagger yaml pusblished on https.
When tried below command got SSLHandshakeError.
"swagger-codegen generate -i https://localhost:443/api/swagger.yaml -l java -o java-api/."
Also when swagger codegen generates client will it have SSL Mutual TLS code for https swagger spec url?
Please help.

Please add -D io.swagger.parser.util.RemoteUrl.trustAll=true when generating the code.
Ref: https://github.com/swagger-api/swagger-codegen/wiki/FAQ#is-there-a-way-to-disable-certificate-verification
UPDATE: On May 2018, about 50 top contributors and template creators of Swagger Codegen decided to fork Swagger Codegen to maintain a community-driven version called OpenAPI Generator. Please refer to the Q&A for more information.

the above answer didn't work for me. if you are facing the same problem as I just use the bellow structure
( "swagger:generate": "SET JAVA_OPTS=-Dio.swagger.parser.util.RemoteUrl.trustAll=true -Dio.swagger.v3.parser.util.RemoteUrl.trustAll=true && openapi-generator generate -i https://xxxxxx/swagger/1.0/swagger.json -g typescript-angular -o ./src/code-gen"
)
that's how I solved it

Related

Is it possible to use a Swagger Spec file with relative paths to other Swagger spec files for a Rapid7 Scan? [duplicate]

I want to combine an API specification written using the OpenAPI 3 spec, that is currently divided into multiple files that reference each other using $ref. How can I do that?
One way to do this is to use the open-source project speccy.
Open the terminal and install speccy by running (requires Node.js):
npm install speccy -g
Then run:
speccy resolve path/to/spec.yaml -o spec-output.yaml
I wrote a quick tool to do this recently. I call it openapi-merge. There is a library and an associated CLI tool:
https://www.npmjs.com/package/openapi-merge
https://www.npmjs.com/package/openapi-merge-cli
In order to use the CLI tool you just write a configuration file and then run npx openapi-merge-cli. The configuration file is fairly simple and would look something like this:
{
"inputs": [
{
"inputFile": "./gateway.swagger.json"
},
{
"inputFile": "./jira.swagger.json",
"pathModification": {
"stripStart": "/rest",
"prepend": "/jira"
}
},
{
"inputFile": "./confluence.swagger.json",
"disputePrefix": "Confluence",
"pathModification": {
"prepend": "/confluence"
}
}
],
"output": "./output.swagger.json"
}
For more details, see the README on the NPM package.
Most OpenAPI tools can work with multi-file OpenAPI definitions and resolve $refs dynamically.
If you specifically need to get a single resolved file, Swagger Codegen can do this. Codegen has a CLI version (used in the examples below), a Maven plugin (usage example) and a Docker image.
The input file (-i argument of the CLI) can be a local file or a URL.
Note: Line breaks are added for readability.
OpenAPI 3.0 example
Use Codegen 3.x to resolve OpenAPI 3.0 files:
java -jar swagger-codegen-cli-3.0.35.jar generate
-l openapi-yaml
-i ./path/to/openapi.yaml
-o ./OUT_DIR
-DoutputFile=output.yaml
-l openapi-yaml outputs YAML, -l openapi outputs JSON.
-DoutputFile is optional, the default file name is openapi.yaml / openapi.json.
OpenAPI 2.0 example
Use Codegen 2.x to resolve OpenAPI 2.0 files (swagger: '2.0'):
java -jar swagger-codegen-cli-2.4.28.jar generate
-l swagger-yaml
-i ./path/to/openapi.yaml
-o ./OUT_DIR
-DoutputFile=output.yaml
-l swagger-yaml outputs YAML, -l swagger outputs JSON.
-DoutputFile is optional, the default file name is swagger.yaml / swagger.json.
I found that the Redocly CLI was a viable option for doing exactly what you need (addressing $ref's used within specifications).
You can configure the CLI using a configuration file (that must be located in the root of your project directory as well as be written in YAML format) which allows you to specify certain linting rules among other things. But to bundle your specifications, simply perform a bundle in the directory of where the configuration file is like so:
redocly bundle -o <NameOfFileOrDir>
After running this command, all of your $ref's will be replaced with the actual code of whatever the $ref was for, combining them into one definition.
If you have multiple elements defined in your apis object in your configuration file (i.e. multiple API definitions), it will create a directory named whatever you specified for the -o option and the folder will contain all of your definitions.

Krakend generate command not found

I am using krakend version 1.4.0 docs say I can run generate commands to get OpenAPI, postman or config to graph.
when I try to run any of these commands. I get
Error: unknown command "generate" for "krakend"
do I need to do something differently to enable generate commands? Heres a link for generator commands. https://www.krakend.io/docs/enterprise/commands/openapi/
You are passing a KrakenD Enterprise documentation link, but you are using the community Edition. There is no command generate on the free version as per 1.4.

How do I make OpenapiGenerator to generate models when defined inline?

I tried running java -jar openapi-generator-cli.jar generate -i 'swagger.json' -g scala-akka -o scala_client but it didn't produce any modules (doesn't work with Java nor Clojure).
Running java -jar openapi-generator-cli.jar generate -c config.yaml -i 'swagger.json' -g scala-akka -o scala_client --generate-alias-as-model (also without config and/or without --generate-alias-as-model), doesn't produce any model libs either.
Removing "additionalProperties": false, from the inline schema def makes it generate model classes. What also works is to define the schema using definitions + "$ref" : "..." - but neither of those are feasible with the library I'm using for my server.
I don't quite understand why it won't generate the models. Can't seem to find an answer anywhere, am I missing something simple?
My swagger.json
Any help would be much appreciated.
I think the only issue is that your are using a 2.0 version of the OpenAPI-Specification. One can easily migrate to version 3.* (try THIS for example), then the models will be generated (for me it worked with scala-akka and java-spring)
transformed_to_3.0.0.json

How to convert a swagger 1.1 spec to a swagger >= 1.2 spec

I'm trying to generate client code for C#/asp.net core to consume a service that has a swagger 1.1 specification. (The service is out of my control). Unfortunately most up-to-date tools require at a swagger 1.2 spec. Most tools even require open-api 2.0. Even most converters start at 1.2. Does anybody know a tool to upgrade from 1.1 to 1.2?
I'd even consider a manual rewrite, but I can't find anywhere what changed between 1.1 and 1.2
First of all, 1.2 is also a very old version. Consider converting to OpenAPI 2.0 (used by most tools nowadays) or maybe even OpenAPI 3.0 (the latest version).
Swagger Codegen
Swagger Codegen can generate client/server code from 1.x-3.0 specs, and can also convert Swagger 1.x to OpenAPI 2.0 or 3.0.
To generate a C# client from a Swagger 1.x spec using Codegen CLI v. 2.x:
java -jar swagger-codegen-cli-2.4.0.jar generate
-i http://path/to/spec.json
-l csharp
-o ./csharp-client
To convert Swagger 1.x to OpenAPI 2.0, Codegen CLI v. 2.x with the -l swagger argument to get JSON or -l swagger-yaml to get YAML.
java -jar swagger-codegen-cli-2.4.0.jar generate
-i http://path/to/spec.json
-l swagger
-o ./converted
To convert to OpenAPI 3.0, use Codegen CLI v. 3.x with the -l openapi argument to get JSON or -l openapi-yaml to get YAML.
java -jar swagger-codegen-cli-3.0.3.jar generate
-i http://path/to/spec.json
-l openapi
-o ./converted
API Transformer
API Transformer claims to support Swagger 1.x -> 1.2 / 2.0 / 3.0 conversion.

How to run swagger-codegen for OpenAPI 3.0.0

looks like official swagger for openapi specification V3 support is near release https://blog.readme.io/an-example-filled-guide-to-swagger-3-2/, and the swagger-codegen has 3.0.0 support developed and passing some level of testing https://github.com/swagger-api/swagger-codegen on the 3.0.0 branch
I have a swagger spec (generated from my existing 2.0 spec via https://github.com/mermade/swagger2openapi, output looks good)
Is there an easy way to run the swagger-codegen without having to package the jar myself?
this is the single result i found: https://oss.sonatype.org/content/repositories/snapshots/io/swagger/swagger-codegen-cli/3.0.0-SNAPSHOT/ but running that seems to be broken (from the output, possibly actually running 2.0 not 3.0.0?):
[main] INFO io.swagger.parser.Swagger20Parser - reading from /input/myspec.openapi3.json
[main] INFO io.swagger.codegen.ignore.CodegenIgnoreProcessor - No .swagger-codegen-ignore file found.
Exception in thread "main" java.lang.RuntimeException: missing swagger input or config!
at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:685)
at io.swagger.codegen.cmd.Generate.run(Generate.java:285)
at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
It looks like the swagger-codegen repo has a somewhat supported way to run a docker container after you build; I'm just hoping/guessing there is a supported way to do this without needing to compile locally, as I need to set this up in several places.
OpenAPI Generator (found by top contributors of Swagger Codegen) supports both OpenAPI specification v2 and v3.
You can use the docker images, Java JAR (SNAPSHOT), Brew or npm to give it a try.
For more information about OpenAPI Generator, please refer to the project's README
If you need any help, please open an issue and we'll look into it.
UPDATE: 1st stable version 3.0.0 has been released: https://github.com/OpenAPITools/openapi-generator/releases/tag/v3.0.0
Swagger-codegen 3.0.0 snapshots now include a limited number of targets for code generation from OpenAPI 3.0 definitions. https://github.com/swagger-api/swagger-codegen/issues/6598#issuecomment-333428808
There is an alternative experimental implementation of the codegen engine, using the original swagger-codegen 2.x templates, written in Node.js: https://github.com/mermade/openapi-codegen - if your language is not yet supported, a config file just needs to be created for it mapping the template files to outputs.

Resources