Avro multiple enum int the same type (avro.SchemaParseException: Can't redefine) - parsing

A have the following avro schema, but if I want to parse it, then I got the following error:
Exception in thread "main" org.apache.avro.SchemaParseException: Can't redefine: ...
{
"name": "card_1_nr",
"type": "string"
}, {
"name": "card_1_type",
"type": {
"name": "card_type",
"type": "enum",
"symbols": ["diamonds", "clubs", "hearts", "spades"],
"default": "diamonds"
}
}, {
"name": "card_2_nr",
"type": "string"
}, {
"name": "card_2_type",
"type": {
"name": "card_type",
"type": "enum",
"symbols": ["diamonds", "clubs", "hearts", "spades"],
"default": "diamonds"
}
}

Just simply need to use the enume type name:
{
"name": "card_1_nr",
"type": "string"
}, {
"name": "card_1_type",
"type": {
"name": "card_type",
"type": "enum",
"symbols": ["diamonds", "clubs", "hearts", "spades"],
"default": "diamonds"
}
}, {
"name": "card_2_nr",
"type": "string"
}, {
"name": "card_2_type",
"type": "card_type"
}

Related

Complex Nested JSON Conversion to Data Table without creating class in C#

{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Title",
"type": "object",
"properties": {
"location": {
"type": "string"
},
"dagno": {
"type": "string"
},
"pattano": {
"type": "string"
},
"pattatype": {
"type": "string"
},
"landclass": {
"type": "string"
},
"bigha": {
"type": "string"
},
"katha": {
"type": "string"
},
"lessa": {
"type": "string"
},
"pid": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"pdarid": {
"type": "string"
},
"pdarname": {
"type": "string"
},
"pdarfather": {
"type": "string"
}
},
"required": [
"pdarid",
"pdarname",
"pdarfather"
]
}
]
}
},
"required": [
"location",
"dagno",
"pattano",
"pattatype",
"landclass",
"bigha",
"katha",
"lessa",
"pid"
]
}

Avro Schema: don't know which "defualt" value to use

One of my fields in my Avro Schema is:
{
"name": "recipients",
"type": {
"type": "array",
"items": {
"name": "recordings",
"type": "record",
"fields": [
{
"name": "returnAddress",
"type": ["null","string"],
"default": null
},
{
"name": "something",
"type": ["null","string"],
"default": null
},
{
"name": "phone",
"type": ["null","string"],
"default": null
},
{
"name": "pfp",
"type": {
"name": "pfp",
"type": "record",
"fields": []
},
"default": {"a": 1}
},
{
"name": "example1",
"type": "int",
"default": -1
},
{
"name": "example2",
"type": "int",
"default": -1
}
]
},
"default": [1]
}
}
However I get an error message :
Field recipients type:ARRAY pos:4 not set and has no default value
Do I need a default value for the recipients field? and if so what would the default value be for the type listed under recipients. I have tried "default":null, "default": {"a":1}, and "default": [1] and all returned errors.

Compatibility of Avro contract with enum

I have an existing avro schema
{
"name": "myenum",
"type": {
"type": "enum",
"name": "Suit",
"symbols": ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"]
},
"default": null
}
I want to add null to be the default and updating the contract to the following result in backward compatibility error. what can be done to solve this issue
{
"name": "myenum",
"type": [ null, {
"type": "enum",
"name": "Suit",
"symbols": ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"]
}],
"default": null
}
There is a problem with the null that is been added.
i.e.
{
"name": "myenum",
"type": [ null, { <- problem
"type": "enum",
"name": "Suit",
"symbols": ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"]
}],
"default": null
}
It should be within quotes: null => "null". So updated definition will be like:
{
"name": "myenum",
"type": [ "null", { <- change
"type": "enum",
"name": "Suit",
"symbols": ["SPADES", "HEARTS", "DIAMONDS", "CLUBS"]
}],
"default": null
}

How to define a schema which have a union in an array in avro?

I want to define my array element as a union. Is it possible? If so please share a sample schema.
I think this is what you are looking for:
Avro Schema:
{
"type": "record",
"namespace": "example.avro",
"name": "array_union",
"fields": [
{
"name": "body",
"type": {
"name": "body",
"type": "record",
"fields": [
{
"name": "abc",
"type": [
"null",
{
"type": "array",
"name": "abc_name_0",
"items": {
"name": "_name_0",
"type": "record",
"fields": [
{
"name": "app_id",
"type": [
"null",
"string"
]
},
{
"name": "app_name",
"type": [
"null",
"string"
]
},
{
"name": "app_key",
"type": [
"null",
"string"
]
}
]
}
}
]
}
]
}
}
]
}
Valid Json that schema can accept:
{
"body": {
"abc": {
"array": [
{
"app_id": {
"string": "abc"
},
"app_name": {
"string": "bcd"
},
"app_key": {
"string": "cde"
}
}
]
}
}
}
Or,
{
"body": {
"abc": null
}
}
You could add this below piece of code as a record field type
{
"name": "some_type",
"type": {
"type": "array",
"items": {
"name": "SomeType",
"type": "record",
"fields": [
{
"name": "name",
"type": ["null", "string"]
},
{
"name": "text",
"type": "string"
},
{
"name": "type",
"type": {
"name": "NamedTextType",
"type": "enum",
"symbols": [ "named_text", "common_named_text" ]
}
}
]
}
}
}
Hope this helps!

Swagger 2.0 - Inconsistent Results From Swagger Source

Swagger source below. When I run the swagger-tools validator, I receive no errors. When I load this in the editor, I see output but it is incorrect - it shows wrong types, and an incomplete Member object. When I try to use the code generator cli java tool, I get the following errors:
711 [main] ERROR io.swagger.models.properties.PropertyBuilder - no property for null, null
712 [main] WARN io.swagger.util.PropertyDeserializer - no property from null, null, {ENUM=null, TITLE=null, DESCRIPTION=null, DEFAULT=null, PATTERN=null, DESCRIMINATOR=null, MIN_ITEMS=null, MAX_ITEMS=null, MIN_PROPERTIES=null, MAX_PROPERTIES=null, MIN_LENGTH=null, MAX_LENGTH=null, MINIMUM=null, MAXIMUM=null, EXCLUSIVE_MINIMUM=null, EXCLUSIVE_MAXIMUM=null, UNIQUE_ITEMS=null, EXAMPLE=null, TYPE=null, FORMAT=null}
822 [main] ERROR io.swagger.codegen.DefaultCodegen - unexpected missing property for name null
822 [main] WARN io.swagger.codegen.DefaultCodegen - skipping invalid property {
"type" : "array"
}
{
"swagger": "2.0",
"info": {
"title": "V1 Inmar CRM API",
"description": "CRM API",
"version": "1.0.0"
},
"produces": ["application/json"],
"basePath": "/v1",
"paths": {
"/member": {
"get": {
"x-swagger-router-controller": "member",
"tags": ["member"],
"operationId": "GetMember",
"parameters": [
{ "$ref": "#/parameters/x-inmar-rest-api-key" },
{ "$ref": "#/parameters/x-inmar-memberID" }
],
"responses": {
"200": {
"description": "success",
"schema": { "$ref": "#/definitions/Member" }
}
}
},
"post": {
"x-swagger-route-controller": "member",
"tags": ["member"],
"operationId": "PostMember",
"parameters": [
{ "$ref": "#/parameters/x-inmar-rest-api-key" },
{ "$ref": "#/parameters/x-inmar-memberID" },
{ "$ref": "#/parameters/member" }
],
"responses": {
"200": { "$ref": "#/responses/generic-200" }
}
}
}
},
"parameters": {
"x-inmar-rest-api-key": {
"name": "X-Inmar-REST-API-Key",
"description": "API Access Key.",
"in": "header",
"required": true,
"type": "string"
},
"x-inmar-memberID": {
"name": "X-Inmar-MemberID",
"description": "Unique ID for member.",
"in": "header",
"required": true,
"type": "string"
},
"member": {
"description": "member object",
"in": "body",
"name": "body",
"required": true,
"schema": {
"$ref": "#/definitions/Member"
}
}
},
"responses": {
"generic-200": {
"description": "Success"
}
},
"definitions": {
"Member": {
"description": "member",
"type": "object",
"properties": {
"active": {
"type": "boolean",
"default": true
},
"identity": {
"type": "object",
"required": [
"user_id"
],
"properties": {
"user_id": {
"type": "string",
"maxLength": 50,
"format": "email"
},
"password": {
"type": "string",
"minLength": 8,
"maxLength": 20
},
"proxy_id": {
"type": "integer"
}
}
},
"pii": {
"type": "object",
"description": "personally_identifiable_information.",
"properties": {
"alt_email": {
"type": "string",
"description": "Secondary email addresses that may or may not match the id.",
"format": "email"
},
"first_name": {
"type": "string",
"minLength": 1,
"maxLength": 25
},
"last_name": {
"type": "string",
"minLength": 1,
"maxLength": 25
},
"primary_address_one": {
"type": "string",
"minLength": 1,
"maxLength": 47
},
"primary_address_two": {
"type": "string",
"minLength": 1,
"maxLength": 47
},
"primary_address_city": {
"type": "string",
"minLength": 1,
"maxLength": 47
},
"primary_address_state": {
"type": "string",
"minLength": 2,
"maxLength": 2,
"description": "US states and US territories and Canadian provinces.",
"enum": [
"AA",
"AB",
"AE",
"AK",
"AL",
"AP",
"AR",
"AS",
"AZ",
"BC",
"CA",
"CO",
"CT",
"DC",
"DE",
"FL",
"FM",
"GA",
"GU",
"HI",
"IA",
"ID",
"IL",
"IN",
"KS",
"KY",
"LA",
"MA",
"MB",
"MD",
"ME",
"MH",
"MI",
"MN",
"MO",
"MP",
"MS",
"MT",
"NB",
"NC",
"ND",
"NE",
"NH",
"NJ",
"NL",
"NM",
"NS",
"NT",
"NU",
"NV",
"NY",
"OH",
"OK",
"ON",
"OR",
"PA",
"PE",
"PR",
"PW",
"QC",
"RI",
"SC",
"SD",
"SK",
"TN",
"TX",
"UK",
"UT",
"VA",
"VI",
"VT",
"WA",
"WI",
"WV",
"WY",
"YT"
]
},
"primary_address_postal_code": {
"type": "string",
"minLength": 5,
"maxLength": 10
},
"primary_address_country": {
"type": "string",
"enum": [
"US",
"CA"
]
},
"birthdate": {
"type": "string"
},
"language_preference": {
"type": "string"
},
"gender": {
"type": "string",
"enum": [
"male",
"female"
]
}
}
},
"profiles": {
"type": "array",
"items": {
"properties": {
"site_id": {
"type": "integer"
},
"survey_data": {
"type": "object",
"required": [
"survey_id",
"survey_responses"
],
"properties": {
"survey_id": {
"type": "integer",
"description": "Unique identifier of a profile survey."
},
"survey_responses": {
"type": "array",
"items": {
"required": [
"question_id",
"response_id",
"free_form_value"
],
"properties": {
"question_id": {
"type": "integer",
"description": "Unique identifier of a profile survey question."
},
"response_id": {
"type": "integer",
"description": "Unique identifier of a profile question response.",
"default": 0
},
"free_form_value": {
"type": "string",
"description": "Consumer free form response",
"default": ""
}
}
}
}
}
}
}
}
},
"optins": {
"type": "array",
"items": {
"$ref": "#/definitions/OptIn"
}
}
}
},
"OptIn": {
"description": "survey response",
"type": "object",
"properties":{
"optin_id": {
"type": "integer",
"description": "Unique identifier of an opt in question/choice. e.g. newsletter"
},
"optin_value": {
"type": "integer",
"enum": [ 0, 1 ],
"description": "Optin Response of 0=Optout and 1=Optin"
}
},
"required": [
"optin_id",
"optin_value"
]
}
}
}

Resources