Swagger documentation: How to update the content of the body - swagger-2.0

I am new to API swagger documentation so looking your support.
I am on the way to generate the curl.
In the swagger editor i have written below code in the definition section
definitions:
Instrument_users:
type: "object"
required:
- "proposal_id"
- "user_id"
- "data_access_role"
properties:
proposal_id:
type: "integer"
example: "244"
user_id:
type: "integer"
example: "1010"
data_access_role:
type: "integer"
example: "2"
default: "2"
xml:
name: "Instrument_users"
which generates body as mentioned below in the right section of the editor
{
"proposal_id": "244",
"user_id": "1010",
"data_access_role": "2"
}
What code do I need to write to expect below body content in the right section of the swagger
{ "proposal_user":
{
"proposal_id": "244",
"user_id": "1010",
"data_access_role": "2"
}}
Thanks

you should write this:
definitions:
Instrument_users:
type: "object"
properties:
proposal_user:
type: "object"
properties:
proposal_id:
type: "string"
example: "244"
user_id:
type: "string"
example: "1010"
data_access_role:
type: "string"
example: "2"

Related

Retrieving attributes from a resource group with a tempate composition

I want to create multiple copies of some resources defined in a template. How do I retrieve the attributes of the resources created in this fashion.
To illustrate, here is a template to create a random string (I call word.yaml):
heat_template_version: rocky
resources:
word:
type: OS::Heat::RandomString
Because I want a list of such random strings, I use an OS::Heat::ResourceGroup calling the template from word.yaml:
heat_template_version: rocky
resources:
composition:
type: OS::Heat::ResourceGroup
properties:
count: 2
resource_def:
type: word.yaml
outputs:
composition:
value: {get_attr: [composition, resource.word]}
Rubbing together the explanation of OS::Heat::ResourceGroup (ResourceGroup) and the template composition documentation (nested attributes), I expected a list of strings in my output, yet I get:
{
"outputs": [
{
"output_key": "composition",
"description": "No description given",
"output_error": "Member 'word' not found in group resource 'composition'.",
"output_value": null
}
]
}
What am I missing about the interaction of the resource group and the template composition?
Found the answer: I need to specify the attribute to retrieve as outpus of the composition. So the word.yaml would look like this:
heat_template_version: rocky
resources:
word:
type: OS::Heat::RandomString
outputs:
word:
description: the word
value: {get_attr: [word]}
And the composition, like so:
heat_template_version: rocky
resources:
composition:
type: OS::Heat::ResourceGroup
properties:
count: 2
resource_def:
type: word.yaml
outputs:
composition:
value: {get_attr: [composition, word]}
Yielding the expected output:
{
"output_key": "composition",
"description": "No description given",
"output_value": [
{
"value": "gB7ZcXgNjJlEtf8N47yFCOQyH0a1bb9c"
},
{
"value": "wXN4jAKgPqbf5i3GDR6qMkzfC7jF0xdC"
}
]
}

Mukle 4 : RAML : how to define the schema of a POST BODY request in a RAML file?

A POST REST request having 3 body params as follows:
{
"name" : "ABC",
"age": 34,
"uniqueID": "12345sdfgh"
}
My requirement is to define constraints (type, maxlength, min length, regex, etc.) for each field name, age and unique id.
How can I define that?
There are some different ways to define it. The 'pure' RAML way it is to define a data type fragment for the data object using RAML definitions for types. Those should cover all your needs.
Example:
dataType.raml
#%RAML 1.0 DataType
type: object
displayName: Booking
properties:
BookingDetail:
type: object
required: true
displayName: "BookingDetail"
description: "BookingDetail"
properties:
Name:
type: string
required: true
displayName: "Name"
description: "Name"
example: "John"
NumberOfDays:
type: integer
required: true
minimum: 1
maximum: 10
API:
#%RAML 1.0
title: so-type
/bookings:
post:
body:
application/json:
type: !include dataType.raml
You can also use JSON schemas if you prefer:
/orders:
post:
body:
application/json:
type: !include schemas/OrdersSchema.json
One more thing, I think. To require input to comply with a regex, you might do this:
properties:
Name:
type: string
required: true
displayName: "Name"
description: "Name"
pattern: ^[-A-Za-z ]+$
example: "John"
That pattern is overly restrictive, but does match many Western traditional names. Your own regex is presumably more carefully constructed.

Power Automate Custom Connector Test thinks file output is a string

My Web API method returns a binary PDF file in the response body and I've set this in the swagger file in the Custom Connector of Power Automate. However, despite the output being a binary PDF file AND that the property type is "file", the Test function in the Custom Connector UI still thinks its returning a "string" even through it clearly isn't!
Question: Any ideas what I'm doing wrong to make the tester think it's a string?
Here is a screenshot of the issue:
Here is my swagger for the Web API method (take note of the 200 response of schema: {type: file, format: binary}:
swagger: '2.0'
info: {title: xxxx, version: '1.0', description: xxxx}
host: xxxx.azurewebsites.net
basePath: /api
schemes: [https]
consumes: []
produces: []
paths:
/FrontPageGenerator:
post:
description: xxxx
operationId: FrontPageGenerator
summary: FrontPageGenerator
parameters:
- name: body
in: body
required: true
schema: {type: string}
consumes: [application/json]
produces: [application/json, application/pdf]
responses:
'200':
description: Successfully generated composite PDF file
schema: {type: file, format: binary}
'400':
description: Invalid input
schema: {$ref: '#/definitions/GenericJson'}
examples:
application/json: {message: No body}
'406':
description: Not Acceptable Accept Type
schema: {$ref: '#/definitions/BasicError'}
examples:
application/json: {message: Not Acceptable}
definitions:
BasicError:
type: object
properties:
message: {type: string}
GenericJson: {type: object}

swagger editor reference definition inside another definition

Inside my definitions I'm using inheritance. In the example below, the PERSON-PATCH properties are coming in without issue. Now I want to take the PERSON-BIO properties and show that's a sub-object inside the PersonGet. I can't figure out the syntax to do that.
PersonBio:
type: object
properties: &PERSON-BIO
nickname:
type: string
description: The nickname for the Person
... other properties chopped out ...
minProperties: 1
PersonGet:
type: object
properties:
<<: *PERSON-PATCH
ident:
type: integer
format: int32
description: The SQL ident of the Person
bio:
<<: *PERSON-BIO
OK, just figured this out;
PersonGet:
type: object
properties:
<<: *PERSON-PATCH
bio:
$ref: '#/definitions/PersonBio'

Autocomplete with Elasticsearch

I’m trying to use Elasticsearch to index a city database and get autocomplete on a field.
Here is my FOSElasticaBundle configuration :
fos_elastica:
indexes:
xxxxxxx:
settings:
index:
analysis:
analyzer:
custom_analyzer:
type: custom
tokenizer: nGram
filter: [lowercase, asciifolding, stopwords_fr, elision, snowball_fr, word_delimiter]
custom_search_analyzer:
type: custom
tokenizer: standard
filter: [lowercase, asciifolding, stopwords_fr, elision, snowball_fr, word_delimiter]
tokenizer:
nGram:
type: nGram
min_gram: 4
max_gram: 20
filter:
snowball_fr:
type: snowball
language: French
elision:
type: elision
articles: [l, m, t, qu, n, s, j, d]
stopwords_fr:
type: stop
stopwords: [_french_]
ignore_case: true
types:
cities:
mappings:
id:
name: { search_analyzer: custom_analyzer, index_analyzer: custom_analyzer, type: string, store: yes }
persistence:
driver: orm
model: XXXXX\MainBundle\Entity\City
provider: { query_builder_method: createSearchIndexQueryBuilder }
listener: ~
finder: ~
repository: XXXXX\SearchBundle\Repository\CitySearchRepository
My query looks like this :
{
"query": {
"match": {
"name": "xxxxxx"
}
}
}
But my problem is here :
When I type “Pa”, I get 242 results (ok)
When I type “Par”, I get no results (WTF)
When I type “Pari”, I get 22 results (ok)
When I type “Paris”, I get 10 results (ok)
It’s my first time with Elasticsearch, I think the solution is nearby, but if somebody has the same issue, I’m curious to know more about it.
Thanks, have a good day ;)
In your query you are doing a match. It means that you will look for documents that have the (analyzed) value you are looking for.
You should have a look on the completion suggester, it is the best way to implement suggestions for autocomplete.
If you are lazy you can just use a prefix query:
{
"prefix" : { "user" : "Pa" }
}

Resources