Use a reference to the same object inside an object - swagger-2.0

I'm trying to do something like this:
User:
type: "object"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
manager:
$ref: "/definitions/User"
Editor does not throw an exception, but the code generated according to this schema does not work at all.
I generated python-flask server, and on launch, it throws:
ImportError: cannot import name 'User'
Looking through the code I found that 'User' class uses 'User' keyword in __init__ and inside the class.
Also there was the import: from swagger_server.models.user import User
Does python-flask generator know how to implement references like this?

Related

Structural error property type should be equal to one of the allowed values allowedValues: string, number, boolean, integer, array in Swagger editor

I'm using springfox 2.9.2 and want test my swagger JSON as YAML in https://editor.swagger.io/
I have property with #ApiParam annotation type: object
#ApiParam(value = "metadata file")
protected Object metadataFile;
but when I test my generated json on swagger editor I got this error:
Structural error at ---.parameters.5.type should be equal to one of
the allowed values allowedValues: string, number, boolean, integer,
array Jump to line ---
there is way to allowed property type object in this section?
the section that trigger the problem
paths:
:
post:
parameters:
name: metadataFile
in: query
description: ...
required: false
type: object
Swagger documentation (go to the bottom of the page): https://swagger.io/docs/specification/2-0/describing-parameters/
"Can I have an object as a query parameter?
This is possible in OpenAPI 3.0, but not in 2.0."

serverless step functions: Getting error when passing more than one fields in the payload for lambda

Error: Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: The value for the field 'Date.$' must be a valid JSONPath at /States/Insert Data Dynamodb/Parameters' (Service: AWSStepFunctions; Status Code: 400; Error Code: InvalidDefinition;
below is the corresponding serverless.yaml code.
I tried wrapping the two parameters into encoded json string and passed it as single payload field and it resulted in the same error but when there is only one plain field in the payload this code deployed successfully
Any suggestions on how to pass two parameters?
service: service-name
frameworkVersion: '2'
provider:
name: aws
runtime: go1.x
lambdaHashingVersion: 20201221
stage: ${opt:stage, self:custom.defaultStage}
region: us-east-1
tags: ${self:custom.tagsObject}
logRetentionInDays: 1
timeout: 10
deploymentBucket: lambda-repository
memorySize: 128
tracing:
lambda: true
plugins:
- serverless-step-functions
configValidationMode: error
stepFunctions:
stateMachines:
sortData:
name: datasorting-dev
type: STANDARD
role: ${self:custom.datasorting.${self:provider.stage}.iam}
definition:
Comment: "Data Sort"
StartAt: Query Data
States:
Query Data:
Type: Task
Resource: arn:aws:states:::athena:startQueryExecution.sync
Parameters:
QueryString: >-
select * from table.data
WorkGroup: primary
ResultConfiguration:
OutputLocation: s3://output/location
Next: Insert Data Dynamodb
Insert Data Dynamodb:
Type: Task
Resource: arn:aws:states:::lambda:invoke
Parameters:
FunctionName: arn:aws:lambda:us-east-1:${account-id}:function:name
Payload:
OutputLocation.$: $.QueryExecution.ResultConfiguration.OutputLocation
Date.$: ${self:custom.dates.year}${self:custom.dates.month}${self:custom.dates.day}
End: true
Your Date.$ property has value of ${self:custom.dates.year}${self:custom.dates.month}${self:custom.dates.day}. Let's assume that:
const dates = {
"year": "2000",
"month": "01",
"day": "20"
}
The result will be Date.$: "20000120" which is not a valid JSON Path.
JSON Path needs to start with a $ sign and each level is divided by ..
Do you want to achieve something like this? $.2000.01.20?
As you see, the issue is not with passing 2 parameters but with wrong string JSON Path created by string interpolation for Date.$.
Some useful links:
https://github.com/json-path/JsonPath
https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-paths.html

Set or Add in Firebase which I need to use for creating a new Database entry?

I want to save User's name in a Database of Firebase called profiles
While I am using the below code it is not creating any entry in my database:
register() {
fb.auth().createUserWithEmailAndPassword(this.email, this.password)
.then((user)=>{
db.collection('profiles').doc(user.user.uid).set({
name: this.profile.name
})
}
I have a profile object. So, it is not a problem.
If I use add like the below, it is creating entry.
db.collection('profiles').add({
name: this.profile.name
})
But Problem is while I am trying to retrieve it's ID, it is not giving me the correct result.
db.collection("profiles").doc(user.uid).update({
name: this.profile.name,
mobile: this.profile.mobile,
postcode: this.profile.postcode
});
uid is not matching.
ERROR:
[Vue warn]: Error in v-on handler: "FirebaseError: [code=invalid-argument]: Function DocumentReference.update() called with invalid data. Unsupported field value: undefined (found in field name)"

How to use "$ref" reference and declare components from Swagger in API platform?

We can define components in Swagger:
components:
schemas:
User:
properties:
id:
type: integer
name:
type: string
And use this component later:
responses:
'200':
description: The response
schema:
$ref: '#/components/schemas/User'
I want to use this in order to avoid duplicating content.
I try to use this syntax in API Platform:
components:
schemas:
Part:
description: Array of Part
type: array
items:
type: object
properties:
name:
type: string
App\Entity\Item:
collectionOperations:
post:
method: 'POST'
swagger_context:
parameters:
- name: body
description: Item data
in: body
schema:
type: object
properties:
name:
description: Part
type: string
required: true
part:
$ref: '#/components/schemas/Part'
It gives me an error:
Exception thrown when handling an exception (Symfony\Component\Config\Exception\FileLoaderLoadException: Resource "components" not found in . (which is being imported from "/app/config/routes/api_platform.yaml"). Make sure there is a loader supporting the "api_platform" type.)
It looks like the YAML loader doesn't recognize the components item.
How can I define and use references in API Platform? How can I define a reference and use it in several YAML files?
You cannot do that like this.
The components key belongs to the Swagger/OpenAPI format, not to the API Platform configuration (mapping) format. Both API Platform configuration files and Swagger definitions can be written in YAML, but they are not related.
So, as the error message describes, Swagger components cannot be injected in API Platform's configuration files directly, as you try to do.
API Platform's configuration does allow allows to inject some context in the generated Swagger file using the swagger_context key, but you cannot write random Swagger definitions (such as your component key) outside of this structure.
To do what you want to achieve the swagger_context key will not be enough (components must be injected at the root of the Swagger file, and it's not possible with swagger_context).
Instead of using this key, you'll have to create a decorator for the Swagger documentation generator, as explained in this documentation entry: https://api-platform.com/docs/core/swagger/#overriding-the-swagger-documentation
Decorator allows to access to the whole Swagger structure, and to modify it. So you'll be able to add your components structure.
It possible ... See How can I annotate my attribute which is Value Object in order that API Platform would generate its fields for swagger documentation?
In my exemple, I have the entity Checker, I created two groups :
* #ApiResource(
* attributes={
* "normalization_context"={"groups"={"read"}},
* "denormalization_context"={"groups"={"write"}},
* },
Then in the swagger_context responses :
* "responses" = {
* "201" = {
* "description" = "....",
* "schema" = {
* "type" = "object",
* "properties" = {
* "myresult" = {
* "$ref"="#/definitions/Checker-read"
* }

Alice Faker library choose random from array

I am trying to generate a dummy data using AliceBundle for Symfony Framework. Everything seems to be working fine except I am looking for a way to randomly assign data from an array to a property called type. Looking at the faker library I can see that I can generate that using randomElement($array = array ('a','b','c'))
I am trying to convert that into YML and I think that is equivalent of
<randomElement(['a','b','c'])>
But this produces an error
[Nelmio\Alice\Throwable\Exception\FixtureBuilder\ExpressionLanguage\LexException]
Could not lex the value "['a'".
This is my complete yml
AppBundle\Entity\Job:
job{1..5}:
title: <jobTitle()>
description: <paragraph(3)>
length: "3_months_full_time"
type: <randomElement(['a','b','c'])>
bonus: <paragraph(3)>
expired_at: "2016-12-21"
job_user: "#emp*"
This works for me:
parameters:
profileArray: ['PUBLIC', 'PRIVATE', 'AUTHENTICATED']
JobPlatform\AppBundle\Entity\Profile:
profiles_{1..100}:
user: '#user_<current()>'
visibility: <randomElement($profileArray)>
I ended up creating a custom provider
namespace AppBundle\DataFixtures\Faker\Provider;
class JobTypeProvider
{
public static function jobType()
{
$types = array("paid", "unpaid", "contract");
$typeIndex = array_rand($types);
return $types[$typeIndex];
}
}
Add that to services.yml
app.data_fixtures_faker_provider.job_type_provider:
class: AppBundle\DataFixtures\Faker\Provider\JobTypeProvider
tags: [ { name: nelmio_alice.faker.provider } ]
And then use it in yml file
AppBundle\Entity\Job:
job{1..50}:
title: <jobTitle()>
description: <paragraph(3)>
length: <jobLength()>
job_industry: "#title*"
type: <jobType()>
bonus: <paragraph(3)>
expired_at: "2016-12-21"
job_user: "#emp*"
Notice type: , this is being generated from service now.

Resources