I am having a problem with the path. The error that i am getting is the following check image below. I tried with the link that was pointed out by a community member #Helen Paths and no luck. Please help me out.
Thanks,
Darko
/opportunity/{opportunityid}/oppproduct/{oppproductid}:
get:
tags:
- "Opportunity"
summary: "Get opp product id for certain opportunity"
description: "This endpoint displays opp product details"
produces:
- "application/json"
parameters:
- name: "opportunityid"
in: "path"
description: "This is unique identifier of specific opportunity"
required: true
type: "string"
- name: "oppproductid"
in: "path"
description: "This is unique identifier of specific opp product in specific opportunity "
required: true
type: "string"
responses:
200:
description: "successful operation"
schema:
type: "array"
items:
$ref: "#/definitions/opportunity"
400:
description: "Invalid status value"
put:
tags:
- "Opportunity"
summary: "Update opportunity product from specific opportunity"
description: "Update this opportunity product."
operationId: "updateOppProduct"
produces:
- "application/json"
parameters:
- name: "opportunityid"
in: "path"
description: "Opportunity product with id that need to be updated"
required: true
type: "string"
responses:
400:
description: "Invalid Opportunity product supplied"
404:
description: "Opportunity product not found"
error that i am getting.
1) "Duplicated mapping key" error indicates you have duplicate keys in one of the parameters, specifically two name keys. You only need one name:
parameters:
- name: "opportunityid" # <---------
in: "path"
description: "Opportunity product with id that need to be updated"
required: true
type: "string"
name: "oppproductid" # <---------
2) The other error is caused by the schema keyword in a path parameter:
- in: "path"
description: "Updated Opp product object"
type: "string" # <--- This is the correct way to specify the param type in OAS 2.0
required: true
schema: # <--------- Remove this
type: integer
You don't need schema here. In OpenAPI 2.0, path, query and header parameters use type directly without the schema keyword.
Related
Parser error, duplicated mapping key, Jump to line 52
Issues while adding common parameter id
Line 44 is over-indented. Replace
/tasks/{id}:
get:
with
/tasks/{id}:
get:
There was a lot to fix.
There were multiple parameters defined in one operation.
The path /tasks/{id} was defined multiple times.
=> You have to use once and put each http-method inside this path.
I tried my best to create the YAML and I hope I fixed it correctly.
It's much easier to do such stuff, if the complete code is part of the question.
openapi: 3.0.1
info:
title: Sample API v2
description: Sample Data API v2
contact:
name: John Smith
email: john.smith#email.com
version: v2
servers:
- url: https://task-manager-pvs.herokuapp.com/
paths:
/tasks:
get:
tags:
- Tasks
summary: Get All Tasks
operationId: GetAllTasks
parameters: []
responses:
'200':
description: ''
headers: {}
deprecated: false
security: []
post:
tags:
- Tasks
summary: Create Task
operationId: CreateTask
parameters: []
requestBody:
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/CreateTaskRequest'
example:
name: test
required: true
responses:
'200':
description: ''
headers: {}
deprecated: false
security: []
/tasks/{id}:
get:
tags:
- Single Task
parameters:
- name: id
in: path
required: true
schema:
type: string
description: The Task ID
summary: Get Single Task
operationId: GetSingleTask
responses:
'200':
description: ''
headers: {}
deprecated: false
security: []
patch:
tags:
- Single Task
summary: Update Task
parameters:
- in: path
name: id
schema:
type: string
required: true
description: The Task ID
operationId: UpdateTask
requestBody:
description: ''
content:
application/json:
schema:
$ref: '#/components/schemas/UpdateTaskRequest'
example:
name: st
required: true
responses:
'200':
description: ''
headers: {}
deprecated: false
security: []
delete:
parameters:
- in: path
name: id
schema:
type: string
required: true
description: The Task ID
tags:
- Single Task
summary: Delete Task
operationId: DeleteTask
responses:
'200':
description: ''
headers: {}
deprecated: false
security: []
components:
schemas:
CreateTaskRequest:
title: CreateTaskRequest
required:
- name
type: object
properties:
name:
type: string
example:
name: test
UpdateTaskRequest:
title: UpdateTaskRequest
required:
- name
type: object
properties:
name:
type: string
example:
name: st
tags:
- name: Tasks
description: ''
- name: Single Task
description: ''
I have a step function that runs 2 separate lambdas. If the step function fails or times out, I want to get an email via SNS telling me the step function failed. I created the event rule using cloudformation and specified the statemachine ARN in the event pattern. When the step function fails, no email is sent out. If I remove the stateMachineArn parameter and run my step function, I get the failure email. I've double checked numerous times that I'm entering the correct ARN for the state machine. CF for the Event Rule is below (in YAML format). Thanks.
FailureEvent:
Type: AWS::Events::Rule
DependsOn:
- StateMachine
Properties:
Name: !Ref FailureRuleName
Description: "EventRule"
EventPattern:
detail-type:
- "Step Functions Execution Status Change"
detail:
status:
- "FAILED"
- "TIMED_OUT"
stateMachineArn: ["arn:aws:states:region:account#:stateMachine:statemachine"]
Targets:
-
Arn:
Ref: SNSARN
Id: !Ref SNSTopic
I did get this fixed and expanded on it to invoke a lambda that publishes a custom SNS email using a lambda. My alignment was off in my EventPattern section. See below. Thanks to #Marcin.
FailureEvent:
Type: AWS::Events::Rule
DependsOn:
- FMIStateMachine
Properties:
Description: !Ref FailureRuleDescription
Name: !Ref FailureRuleName
State: "ENABLED"
RoleArn:
'Fn::Join': ["", ['arn:aws:iam::', !Ref 'AWS::AccountId', ':role/', !Ref LambdaExecutionRole]]
EventPattern:
detail-type:
- "Step Functions Execution Status Change"
detail:
status:
- "FAILED"
- "TIMED_OUT"
stateMachineArn: [!Ref StateMachine]
Targets:
- Arn:
'Fn::Join': ["", ['arn:aws:lambda:', !Ref 'AWS::Region', ':', !Ref 'AWS::AccountId', ':function:', !Ref FailureLambda]]
Id: !Ref FailureLambda
Input: !Sub '{"failed_service": "${StateMachineName}","sns_arn": "arn:aws:sns:${AWS::Region}:${AWS::AccountId}:${SNSTopic}"}'
This question already has answers here:
Swagger: How to have a property reference a model in OpenAPI 2.0 (i.e. nest the models)?
(2 answers)
Closed 2 years ago.
I'm trying to describe an API endpoint that receives a PUT request with the following JSON payload:
{
"product": {
"name: "foo",
"brand": "bar"
}
}
Here is a sample of the definition:
components:
schemas:
Product:
type: object
required:
- name
- brand
properties:
name:
type: string
brand:
type: string
paths:
/products/{id}:
parameters:
- name: id
in: path
schema:
type: integer
required: true
put:
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Product'
However, this produces the following JSON payload (it's missing the "product" key):
{
"name: "foo",
"brand": "bar"
}
I tried this:
parameters:
- name: product
in: body
schema:
type: object
properties:
product:
type: object
schema:
$ref: '#/components/schemas/Product'
But that doesn't work. Any ideas?
Your second example is almost correct, just change this part
schema:
type: object
properties:
product:
type: object
schema:
$ref: '#/components/schemas/Product'
to
schema:
type: object
properties:
product:
$ref: '#/components/schemas/Product'
Note the $ref is used directly under the property name.
I am unable to run the kotlin-server generated by Swagger Codegen v. 3.
The .yaml file is:
openapi: 3.0.0
info:
title: Experiement with Swagger
description: Test
version: 1.0.0
servers:
- url: 'http://localhost:8080'
description: production server's url
tags:
- name: Test
description: Test
externalDocs:
description: Find out more
url: 'http://localhost:8080'
paths:
/testURI:
post:
tags:
- Test
summary: Test
description: Test
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Test'
responses:
'200':
description: Test success
content:
application/json:
schema:
$ref: '#/components/schemas/TestSuccessResponse'
'404':
description: >-
Only a signed in user can add a question. This response means that
the user isn't signed in.
content:
application/json:
schema:
$ref: '#/components/schemas/UnauthorisedErrorResponse'
'500':
description: >-
means some internal error occur on the server while doing the
operation. The state of the operation if un-determined and the
operation could be succesful, failed or partially successful
(because some database operations are not rolled back if error
occurs!
content:
application/json:
schema:
$ref: '#/components/schemas/InternalServerErrorResponse'
components:
schemas:
Test:
type: object
properties:
some-input:
type: string
TestSuccessResponse:
type: object
properties:
result:
type: string
enum:
- success
additional-info:
type: string
enum:
- Test successful
required:
- result
- additional-info
UnauthorisedErrorResponse:
type: object
properties:
result:
type: string
enum:
- error
additional-info:
type: string
enum:
- Not authorised
required:
- result
- additional-info
InternalServerErrorResponse:
type: object
properties:
result:
type: string
enum:
- error
additional-info:
type: string
enum:
- Internal Server Error
required:
- result
- additional-info
I pasted it into Swagger Editor, downloaded the kotlin-server kotlin-server-server-generated.zip, unzipped it at C:\Users\manu\Documents\manu\kotlin-server-server-generated, opened Readme.MD file and followed the instructions in it.
Using Windows cmd, in C:\Users\manu\Documents\manu\kotlin-server-server-generated,
first I ran gradle wrapper.
I got this output:
Starting a Gradle Daemon, 1 incompatible and 2 stopped Daemons could not be reused, use --status for details
Build cache is an incubating feature.
BUILD SUCCESSFUL in 17s
1 actionable task: 1 executed
Then I ran gradlew check assemble:
C:\Users\manu\Documents\manu\kotlin-server-server-generated>gradlew check assemble
Starting a Gradle Daemon, 1 incompatible and 2 stopped Daemons could not be reused, use --status for details
Build cache is an incubating feature.
w: C:\Users\manu\Documents\manu\kotlin-server-server-generated\src\main\kotlin\io\swagger\server\apis\TestApi.kt: (51, 9): Variable 'gson' is never used
w: C:\Users\manu\Documents\manu\kotlin-server-server-generated\src\main\kotlin\io\swagger\server\apis\TestApi.kt: (52, 9): Variable 'empty' is never used
Task :startShadowScripts
Using TaskInputs.file() with something that doesn't resolve to a File object has been deprecated and is scheduled to be removed in Gradle 5.0. Use TaskInputs.files() instead.
BUILD SUCCESSFUL in 36s
10 actionable tasks: 10 executed
Then I ran java -jar ./build/libs/kotlin-server.jar.
But when I pointed the browser to localhost:8080, I see Page Not Found.
What am I doing wrong?
I'm getting the error Data does not match any schemas from 'oneOf' with the following spec:
product: 1.0.0
info:
name: account-information
title: Account Information
version: 1.0.10
termsOfService: >-
These API are a PSD2 implementation example. The service might be
discontinued at any time
visibility:
view:
type: public
subscribe:
type: authenticated
plans:
premium:
title: Premium
apis: {}
rate-limit:
value: 1000/1minute
hard-limit: true
approval: true
default:
title: Default Plan
description: Default Plan
approval: false
rate-limit:
value: 100/hour
hard-limit: true
apis:
account:
$ref: account.yaml
subscription:
$ref: subscription.yaml
The full error message:
Message : "Data does not match any schemas from "oneOf"", Chemin de données : "", Chemin de schéma : "/oneOf"
Message : "Additional properties not allowed", Chemin de données : "/name", Chemin de schéma : "/oneOf/0/additionalProperties"
I don't understand where does the error come from and how to solve it.
For API Connect I believe you want to use x-ibm-name instead of name. I was able to get the following spec validated using your above example:
info:
title: Account Information
x-ibm-name: account-information
version: 1.0.10
visibility:
view:
type: public
subscribe:
type: authenticated
plans:
premium:
title: Premium
apis: {}
rate-limit:
value: 1000/1minute
hard-limit: true
approval: true
default:
title: Default Plan
description: Default Plan
approval: false
rate-limit:
value: 100/hour
hard-limit: true
apis:
account:
$ref: account.yaml
subscription:
$ref: subscription.yaml
Note: I also removed the product field.
You could also use the Design tab to have API Connect create the source automatically in the correct format: