I'm trying to use Swagger Codegen for my OAS3 project.
I have cloned swagger-codegen branch 3.0.0. and when I run the generate command I get the following error:
[main] ERROR io.swagger.parser.SwaggerCompatConverter - failed to read resource listing
com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'openapi': was expecting ('true', 'false' or 'null')
at [Source: (String)"openapi: 3.0.0
Does Codegen supports openapi 3.0.1 yet? If yes what am I missing ?
UPDATE - Yaml file and codegen command
Petstore.yaml file :
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
license:
name: MIT
servers:
- url: http://petstore.swagger.io/v1
paths:
/pets:
get:
summary: List all pets
operationId: listPets
tags:
- pets
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: integer
format: int32
responses:
'200':
description: A paged array of pets
headers:
x-next:
description: A link to the next page of responses
schema:
type: string
content:
application/json:
schema:
$ref: "#/components/schemas/Pets"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
summary: Create a pet
operationId: createPets
tags:
- pets
responses:
'201':
description: Null response
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:
schemas:
Pet:
type: object
required:
- id
- name
properties:
id:
type: integer
format: int64
name:
type: string
tag:
type: string
Pets:
type: array
items:
$ref: "#/components/schemas/Pet"
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
Codegen command:
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
java -jar ./swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i "./definitions/petstoreV3.yaml" -l javascript -o "$SCRIPT_DIR/.swagger_gen_temp"
The error occurs because you are running V2 codegen (from the master branch) instead of V3 codegen (from the 3.0.0 branch). V2 codegen does not support OpenAPI 3.0.
You can download the JAR of V3 codegen from:
http://central.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.11/swagger-codegen-cli-3.0.11.jar
V3 codegen, however, does not currently have a JavaScript client generator.
Related
I have a yaml file which has examples for request body. but swagger-ui springfox generated json file generated by springfox doesn't show the request body example, which makes it to show schema example.
Any workaround for displaying request body examples?
#openapi #swagger-ui #springfox
openapi: 3.0.2
info:
title: Rule APIs
description: Rule APi
version: 1.0.0
contact:
email: abc#gmail.com
servers:
- url: 'https://{server}/v1/rule'
variables:
server:
default: localhost
security:
- BasicAuth: []
paths:
#####################################################################################################
############################ Rule APIs ###############################
#####################################################################################################
/rule-set:
parameters:
- $ref: '#/components/parameters/XRequestIdHeader'
post:
summary: Create a rule set.
description: Create a rule set.
operationId: createRule
tags:
- Rule
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/RuleSet'
example:
name: My RuleSet
description: A new ruleSet
state: enabled
condition:
conditionType: ConditionAttributes
isNegate: false
dictionaryName: DEVICE
attributeName: attribute
operator: equals
attributeValue: attribute
serviceName: service
isProxy: false
responses:
'201':
$ref: '#/components/responses/BadRequest'
'400':
$ref: '#/components/responses/BadRequest'
json output
I have declared a mapping named StageMap in my sam.yaml file:
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Parameters:
ProjectName:
Type: String
SubProjectName:
Type: String
Stage:
Type: String
AllowedValues:
- dev
- test
- preprod
- prod
...
Mappings:
StageMap:
dev:
AuthorizerArn: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:auth-bk-main-dev-AuthorizerFunction-1RR2YJ5STBUB6/invocations
test:
AuthorizerArn: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:auth-bk-main-test-AuthorizerFunction-UQ1EQ2SP5W6G/invocations
preprod:
AuthorizerArn: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:auth-bk-main-preprod-AuthorizerFunction-UQ1W6EQ2SP5G/invocations
prod:
AuthorizerArn: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:auth-bk-main-prod-AuthorizerFunction-5STBUB61RR2YJ/invocations
I would like to use this mapping in my swagger.yaml I have tried the following:
...
x-amazon-apigateway-authorizer:
type: request
authorizerUri:
Fn::FindInMap:
- 'StageMap'
- Ref: 'Stage'
- 'AuthorizerArn
I also tried this solution but I got an error Every Mappings attribute must be a String or a List.
Can you please let me know how to access one of the values in the mapping in the swagger.yaml? Thanks!
I found the following in the AWS SAM docs:
You cannot include parameters, pseudo parameters, or intrinsic functions in the Mappings section.
So I changed:
AuthorizerArn: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:auth-bk-main-dev-AuthorizerFunction-1RR2YJ5STBUB6/invocations
For:
AuthorizerFunctionName: auth-bk-main-dev-AuthorizerFunction-1RR2YJ5STBUB6
And in the swagger.yaml I used the following:
x-amazon-apigateway-authorizer:
type: request
authorizerUri:
Fn::Sub:
- arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${AuthorizerFunctionName}/invocations
- AuthorizerFunctionName:
Fn::FindInMap:
- 'StageMap'
- Ref: 'Stage'
- 'AuthorizerFunctionName'
I want to use swagger to document our internal Jenkins Jobs and parameters. So that everybody knows what the body has to look like to properly trigger a Jenkins jobs over the API.
I am writing the API documentation with a swagger.yml file. Where I am totally struggling is to document nested objects.
Jenkins needs the parameters in JSON. The curl request looks like this
curl --request POST \
--url https://myjenkins.com/job/demojob/build \
--form 'json={
"parameter": [
{
"name": "FilePath",
"value": "E:\\Jenkins"
},
{
"name": "FileName",
"value": "JenkinsAPI.txt"
},
{
"name": "FileContent",
"value": "I am a file created by jenkins through API"
},
{
"name": "Computer",
"value": "myhost"
}
]
}'
I am able to create a yml file that contains something like this, and that does not resemble what I need at all.
Can somebody point me in the right direction, or give me an example?
paths:
/job/demojob/build:
post:
summary: triggers the job
parameters:
- name: parameters
in: body
required: true
- name: filePath
in: body
schema:
type: string
default: "C:\\fancyfolder"
Please check below mentioned yml file with swagger properties mapping and you can change ApiResponse according to your requirement. :
openapi: 3.0.1
info:
title: Swagger Jenkins
description: 'This is a sample server Jenkins server. You can find out more about Swagger'
version: 1.0.0
servers:
- url: https://jenkins.com
tags:
- name: build
description: Everything about your build
paths:
/job/demojob/build:
post:
tags:
- build
summary: build the given branch
operationId: build
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/RequestParameters'
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/ApiResponse'
components:
schemas:
RequestParameters:
type: array
items:
$ref: '#/components/schemas/Parameters'
Parameters:
type: object
properties:
name:
type: string
value:
type: string
description: Order Status
ApiResponse:
type: object
properties:
code:
type: integer
format: int32
type:
type: string
message:
type: string
I have two serverless app which are sharing the same custom authorizer. Suddenly the import function in the second serverless.yml file stopped working.
The app is based on https://github.com/medwig/serverless-shared-authorizer
gateway.serverless
service: authorizer-stack
provider:
name: aws
runtime: nodejs12.x
region: ap-south-1
profile: xxx-dev
functions:
authorizer:
handler: handler.auth
test:
handler: handler.privateEndpoint
events:
- http:
path: /api/test
method: get
authorizer:
type: CUSTOM
authorizerId:
Ref: Authorizer
test2:
handler: handler.publicEndpoint
events:
- http:
path: /api/test/public
method: get
resources:
Resources:
AuthorizerPermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName:
Fn::GetAtt: AuthorizerLambdaFunction.Arn
Action: lambda:InvokeFunction
Principal:
Fn::Join: ["",["apigateway.", { Ref: "AWS::URLSuffix"}]]
Authorizer:
DependsOn:
- ApiGatewayRestApi
Type: AWS::ApiGateway::Authorizer
Properties:
Name: ${self:provider.stage}-Authorizer
RestApiId: { "Ref" : "ApiGatewayRestApi" }
Type: TOKEN
IdentitySource: method.request.header.Authorization
AuthorizerResultTtlInSeconds: 300
AuthorizerUri:
Fn::Join:
- ''
-
- 'arn:aws:apigateway:'
- Ref: "AWS::Region"
- ':lambda:path/2015-03-31/functions/'
- Fn::GetAtt: "AuthorizerLambdaFunction.Arn"
- "/invocations"
Outputs:
AuthorizerId:
Value:
Ref: Authorizer
Export:
Name: authorizerId
apiGatewayRestApiId:
Value:
Ref: ApiGatewayRestApi
Export:
Name: restApiId
apiGatewayRestApiRootResourceId:
Value:
Fn::GetAtt:
- ApiGatewayRestApi
- RootResourceId
Export:
Name: rootResourceId
products serverless
service: products-list
provider:
name: aws
runtime: nodejs12.x
region: ap-south-1
profile: xxx-dev
apiGateway:
restApiId:
Fn::ImportValue: authorizer-stack-dev-restApiId
restApiRootResourceId:
Fn::ImportValue: authorizer-stack-dev-rootResourceId
functions:
get-products:
handler: handler.getProducts
events:
- http:
path: /api/products
method: get
authorizer:
type: CUSTOM
authorizerId:
Fn::ImportValue: authorizer-stack-dev-authorizerId
I am getting the following errors at random
An error occurred: products-list-dev - No export named authorizer-stack-dev-restApiId found.
An error occurred: products-list-dev - No export named authorizer-stack-dev-rootResourceId found.
An error occurred: products-list-dev - No export named authorizer-stack-dev-authorizerId found.
What am I missing here?
serverless -v
Framework Core: 1.74.1
Plugin: 3.6.15
SDK: 2.3.1
Components: 2.31.10
From the shared authorizers I have configured in the past it is not necessary to go to the effort you have undergone. The documentation on the Serverless Framework site has a much simpler setup to achieve a shared authoriser and I will always go with the simplest solution possible: https://www.serverless.com/framework/docs/providers/aws/events/apigateway#share-authorizer
I am new to CloudbaseInit. I have setup a image with CloudbaseInit,and can build the machine with new password and expand hdd size all ok (using command :nova boot). But I want to use heat stack-create with a heat template file
heat_template_version: 2013-05-23
description: dtb test hottest,for test add parameters.
parameters:
flavor:
type: string
label: paasflavor
description: paasflavor flavor to be used
default: c1m2h90
availability_zone:
type: string
description: The Availability Zone to launch the instance.
default: nova
name:
type: string
description: name of host.
resources:
server1_port1:
type: OS::Neutron::Port
properties:
network_id: 70c1faf0-51f6-4cb9-b324-7bc2cc6fab5b
server1:
type: OS::Nova::Server
properties:
name: { get_param: name }
image: template_win2008
flavor: { get_param: flavor }
availability_zone: { get_param: availability_zone }
networks:
- port: { get_resource: server1_port1 }
user_data:
echo 11 > \"c:\\yp\\333"\n,
outputs:
server1_ip:
description: Private IP address of server1
value: { get_attr: [ server1, first_address ] }
Machine builds ok. When I login into it, and go to c:\yp, I find nothing. I think user_data is wrong, and command not work. I have tried several other ways for writing user_data part, but all failed. I never build windows machine with heat template.
Add pipe(|) after user_data:
user_data: |