export class AdministratorLoginDto {
#ApiProperty()
userName: number[];
}
I set userName with number[], but i get the openapi is string[].
I set userName with number[], but i get the openapi json is string[].
{
"AdministratorLoginDto": {
"type": "object",
"properties": {
"userName": {
"type": "array",
"items": {
"type": "string" // question: why this type is not number?
}
}
},
"required": [
"userName"
]
}
}
Thank you!
Try this :
export class AdministratorLoginDto {
#ApiProperty({
type: Number,
isArray: true,
})
userName: number[];
}
Related
I'm new to API Connect, and I haven't been able to find the correct mapping to pass from an array of objects to an object, evaluating its content.
I explain:
I have as input a json like this:
{
"methodCall": {
"methodName": {
"$": "ThisIsTheMethodName"
},
"params": {
"param": {
"value": {
"array": {
"data": {
"value": {
"struct": {
"member": [
{
"name": {
"$": "message"
},
"value": {
"string": {
"$": "Some text to send to client"
}
}
},
{
"name": {
"$": "phone"
},
"value": {
"string": {
"$": "9876543120124"
}
}
},
{
"name": {
"$": "date"
},
"value": {
"string": {}
}
},
{
"name": {
"$": "appid"
},
"value": {
"string": {
"$": "Application Identificator"
}
}
},
{
"name": {
"$": "costCenter"
},
"value": {
"string": {
"$": "102030"
}
}
},
{
"name": {
"$": "filled"
},
"value": {
"string": {
"$": "filledString"
}
}
}
]
}
}
}
}
}
}
}
}
}
and I need to generate this json output from the mapping:
{
"phoneNumberSMS":"983849780",
"message":"Some text to send to client",
"date": "2022-10-04T15:30:00",
"appId":"Application Identificator",
"costCenter":"102030",
"filled":"filledString" }
I have tried with the following configuration, but without success:
On the YAML
actions:
- set: output.phoneNumberSMS
foreach: input.methodCall.params.param.value.array.data.value.struct.member.value.string
from:
- input.methodCall.params.param.value.array.data.value.struct.member.name.$
- input.methodCall.params.param.value.array.data.value.struct.member.value.string.$
values: |-
var retValue1 = '';
if($(input.methodCall.params.param.value.array.data.value.struct.member.name.$) == 'phone'){
retValue1=input.methodCall.params.param.value.array.data.value.struct.member.value.string.$;
}
retValue1;
I appreciate your help !!
I solve this in two phases of mapping:
Create an array called members, where each node is of type member, which has name and value properties.
This 'members' array is the receiver of the data coming from the request.
In the second phase of the mapping, I took the output variable from the previous mapping (of type members) and assigned it to message.body.
This with the aim of getting rid of the field names with a dollar symbol ($), so the mapping will not give any error for not recognizing it.
I'm generating swagger json file using protoc-gen-swagger with gRPC service. The output json is being generated with empty response examples, I want to add response examples to the definition so it gets automatically populated in the generated json.
This is my current definition.
service UserService {
rpc GetUser (GetUserRequest) returns (UserResponse){
option (google.api.http) = {
get: "/api/v1/user/{username}"
response_body: "*"
};
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_operation) = {
description: "Returns user object";
operation_id: "get_user";
summary: "Get User";
};
}
}
message GetUserRequest {
string username = 1;
}
message UserResponse {
User user = 1;
}
message User {
string first_name = 1;
string last_name = 2;
string username = 3;
}
When I generate the swagger file using the command
protoc -I ${PROTOPATH} \
-I $GOPATH/src \
--swagger_out=logtostderr=true:${OUT_PATH}
I get a swagger file with this user object definition
"User": {
"type": "object",
"properties": {
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
},
"username": {
"type": "string"
},
}
}
What I want is to generate it with example values like this:
"User": {
"type": "object",
"properties": {
"first_name": {
"type": "string",
"example": "Adam"
},
"last_name": {
"type": "string",
"example": "Smith"
},
"username": {
"type": "string",
"example": "asmith79"
},
}
}
Found the answer to this here: https://github.com/grpc-ecosystem/grpc-gateway/blob/master/examples/internal/proto/examplepb/a_bit_of_everything.proto#L197
Simple by adding grpc.gateway.protoc_gen_swagger.options.openapiv2_schema as an option to the message.
import "protoc-gen-swagger/options/annotations.proto";
message User {
option (grpc.gateway.protoc_gen_swagger.options.openapiv2_schema) = {
example: { value: '{ "first_name": "Adam", "last_name":"Smith", "username":"asmith79"}' }
};
string first_name = 1;
string last_name = 2;
string username = 3;
}
I have a JSON file for OpenAPI 3 that contains the following:
"trait_hasProjectResponse_200": {
"description": "",
"content": {
"application/xml": {
"example": {
"value" : "<project><foo>1</foo><bar>2</bar></project>"
}
}
}
},
This results in the following display on the current swagger-ui:
How do I specify an example of XML for a parameter or response in the OpenAPI 3 spec? I have looked through the documentation and it seems to be targest mostly at JSON. What do I need to do the my output that is generating the OpenAPI 3 JSON file.
I have also tried to use the externalValue and have has similar difficulties.
Remove the value key from the example (value is only used with multiple examples).
"example": "<project><foo>1</foo><bar>2</bar></project>"
Alternatively, you can define a schema for the response, and Swagger UI will generate examples based on the schema. In your example, the schema is a project object that contains the foo array. You can specify [1, 2] as the example values for the foo array:
"components": {
"responses": {
"trait_hasProjectResponse_200": {
"description": "",
"content": {
"application/xml": {
"schema": {
"$ref": "#/components/schemas/project"
}
}
}
}
},
"schemas": {
"project": {
"type": "object",
"properties": {
"foo": {
"type": "array",
"items": {
"type": "integer"
},
"xml": {
"wrapped": false
},
"example": [1, 2]
}
}
}
}
}
This will give you:
Currently, my swagger definition has :
"MyAttribute": {
"type": "string",
"default": "item1",
"enum": [
"item1",
"item2"
],
"xml": {
"attribute": true
}
},
Swagger codegen generates this java code:
#XmlEnum(String.class)
public enum MyAttribute{
#XmlEnumValue("item1")
item1("item1"),
#XmlEnumValue("item2")
item2("item2");
private String value;
/**
* #param value the string representation of the map specification type attribute
*/
MyAttribute(final String value) {
this.value = value;
}
#Override
public String toString() {
return String.valueOf(value);
}
}
Now, I want to have a string array(with values) instead of enum.
I tried this (but shows errors on swagger website : http://editor.swagger.io/)
"MyAttribute": {
"type": "array",
"items": {
"type": "string",
"values": [
"item1",
"item2"
]
},
"xml": {
"attribute": true
}
}
How to achieve this?
I am using elasticsearch-model (https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model) but I can't find a way to set the TTL on the documents. I have tried a few ways but without success.
I have a model called "log" and an index called "logs". In the model I have the following mappings:
include Elasticsearch::Model
mappings _ttl: { enabled: true, default: '7d' }
Which I was hoping it would be similar to https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-ttl-field.html#mapping-ttl-field
In the console, this is what I can see:
> Log.mappings
=> #<Elasticsearch::Model::Indexing::Mappings:0x007fcefd985368 #mapping={}, #options={:_ttl=>{:enabled=>true, :default=>"7d"}}, #type="log">
However, when using cURL, I can only the model properties and not the ttl option:
curl -XGET 'http://localhost:9200/logs/_mappings'
{
"logs": {
"mappings": {
"log": {
"properties": {
"created_at": {
"format": "dateOptionalTime",
"type": "date"
},
"id": {
"type": "long"
},
"operation": {
"type": "string"
},
"order_number": {
"type": "string"
},
"request_payload": {
"type": "string"
},
"response_payload": {
"type": "string"
},
"updated_at": {
"format": "dateOptionalTime",
"type": "date"
}
}
}
}
}
}
I've also tried to add the TTL option to the bulk import as an option (to achieve this: https://www.elastic.co/guide/en/elasticsearch/reference/1.4/docs-bulk.html#bulk-ttl) but I can't use that option:
> Log.import({
query: -> { where(id: ids) },
refresh: true,
return: 'errors',
ttl: '1d'
})
Unknown key: :ttl. Valid keys are: :start, :batch_size : {"ids":[358]}
Any idea on how I can do this?