Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example pokeapi with new protocol #17489

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Regexes are purely illustrative and need to be workshopped: BC dates shouldn't require 4-digit years; years may have >=5 digits; etc
definitions:
String:
type: string
description: Arbitrary text
BinaryData:
type: string
description: >
Arbitrary binary data. Represented as base64-encoded strings in the JSON transport.
In the future, if we support other transports, may be encoded differently.
# All credit to https://stackoverflow.com/a/475217 for this pattern
pattern: (?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?
Date:
type: string
# format: date is a superset of what we want, so we cannot use it here (e.g. it accepts 2-digit years)
pattern: \d{4}-\d{2}-\d{2}( BC)?
TimestampWithTimezone:
type: string
# format: date-time is a superset of what we want, so we cannot use it here (e.g. it accepts 2-digit years)
pattern: \d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{1,2}(:\d{2})?)( BC)?
description: An instant in time. Frequently simply referred to as just a timestamp, or timestamptz.
TimestampWithoutTimezone:
type: string
pattern: \d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(\.\d+)?( BC)?
description: Also known as a localdatetime, or just datetime.
TimeWithTimezone:
type: string
pattern: \d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-]\d{1,2}(:\d{2})?)
TimeWithoutTimezone:
type: string
pattern: \d{2}:\d{2}:\d{2}(\.\d+)?
Number:
type: string
# Note the mix of regex validation for normal numbers, and enum validation for special values
oneOf:
- pattern: -?(0|[0-9]\d*)(\.\d+)?
- enum:
- Infinity
- -Infinity
- NaN
Integer:
type: string
oneOf:
- pattern: -?(0|[0-9]\d*)
- enum:
- Infinity
- -Infinity
- NaN
Boolean:
# Note the direct usage of a primitive boolean rather than string. Unlike Numbers and Integers, we don't expect unusual values here.
type: boolean
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,45 @@
"type": "object",
"properties": {
"id": {
"type": ["null", "integer"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null is redundant: these properties aren't required, so the source can just not set them at all.

If we find that sources actually want to output {"id": null}, then we can always update the well-known types to use type: [null, integer].

"$ref": "WellKnownTypes.json#definitions/Integer"
},
"name": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"base_experience": {
"type": ["null", "integer"]
"$ref": "WellKnownTypes.json#definitions/Integer"
},
"height": {
"type": ["null", "integer"]
"$ref": "WellKnownTypes.json#definitions/Integer"
},
"is_default ": {
"type": ["null", "boolean"]
"$ref": "WellKnownTypes.json#definitions/Boolean"
},
"order": {
"type": ["null", "integer"]
"$ref": "WellKnownTypes.json#definitions/Integer"
},
"weight": {
"type": ["null", "integer"]
"$ref": "WellKnownTypes.json#definitions/Integer"
},
"abilities": {
"type": ["null", "array"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as seen here: non-primitive types (arrays, objects, oneof, etc) are not defined in WellKnownTypes, because they need additional configuration to fully describe their contents

"items": {
"type": ["null", "object"],
"properties": {
"is_hidden": {
"type": ["null", "boolean"]
"$ref": "WellKnownTypes.json#definitions/Boolean"
},
"slot": {
"type": ["null", "integer"]
"$ref": "WellKnownTypes.json#definitions/Integer"
},
"ability": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"url": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
}
}
}
Expand All @@ -54,10 +54,10 @@
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"url": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
}
}
}
Expand All @@ -68,16 +68,16 @@
"type": ["null", "object"],
"properties": {
"game_index": {
"type": ["null", "integer"]
"$ref": "WellKnownTypes.json#definitions/Integer"
},
"version": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"url": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
}
}
}
Expand All @@ -93,10 +93,10 @@
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"url": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
}
}
},
Expand All @@ -109,15 +109,15 @@
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"url": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
}
}
},
"rarity": {
"type": ["null", "integer"]
"$ref": "WellKnownTypes.json#definitions/Integer"
}
}
}
Expand All @@ -126,7 +126,7 @@
}
},
"location_area_encounters": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"moves": {
"type": ["null", "array"],
Expand All @@ -137,10 +137,10 @@
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"url": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
}
}
},
Expand All @@ -153,26 +153,26 @@
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"url": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
}
}
},
"version_group": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"url": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
}
}
},
"level_learned_at": {
"type": ["null", "integer"]
"$ref": "WellKnownTypes.json#definitions/Integer"
}
}
}
Expand All @@ -184,39 +184,39 @@
"type": ["null", "object"],
"properties": {
"front_default": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"front_shiny": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"front_female": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"front_shiny_female": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"back_default": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"back_shiny": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"back_female": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"back_shiny_female": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
}
}
},
"species": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"url": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
}
}
},
Expand All @@ -229,18 +229,18 @@
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"url": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
}
}
},
"effort": {
"type": ["null", "integer"]
"$ref": "WellKnownTypes.json#definitions/Integer"
},
"base_stat": {
"type": ["null", "integer"]
"$ref": "WellKnownTypes.json#definitions/Integer"
}
}
}
Expand All @@ -251,16 +251,16 @@
"type": ["null", "object"],
"properties": {
"slot": {
"type": ["null", "integer"]
"$ref": "WellKnownTypes.json#definitions/Integer"
},
"type": {
"type": ["null", "object"],
"properties": {
"name": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
},
"url": {
"type": ["null", "string"]
"$ref": "WellKnownTypes.json#definitions/String"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
Copy link
Contributor Author

@edgao edgao Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is just the JSON-ified version of WellKnownTypes.yaml. In the real usage, this file will be provided as part of the CDK - I'm copying it in manually because I don't want to set up the full yaml -> json -> copy pipeline just for this example.

"definitions": {
"String": {
"type": "string",
"description": "Arbitrary text"
},
"BinaryData": {
"type": "string",
"description": "Arbitrary binary data. Represented as base64-encoded strings in the JSON transport. In the future, if we support other transports, may be encoded differently.\n",
"pattern": "(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?"
},
"Date": {
"type": "string",
"pattern": "\\d{4}-\\d{2}-\\d{2}( BC)?"
},
"TimestampWithTimezone": {
"type": "string",
"pattern": "\\d{4}-\\d{2}-\\d{2}[T ]\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{1,2}(:\\d{2})?)( BC)?",
"description": "An instant in time. Frequently simply referred to as just a timestamp, or timestamptz."
},
"TimestampWithoutTimezone": {
"type": "string",
"pattern": "\\d{4}-\\d{2}-\\d{2}[T ]\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?( BC)?",
"description": "Also known as a localdatetime, or just datetime."
},
"TimeWithTimezone": {
"type": "string",
"pattern": "\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{1,2}(:\\d{2})?)"
},
"TimeWithoutTimezone": {
"type": "string",
"pattern": "\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?"
},
"Number": {
"type": "string",
"oneOf": [
{
"pattern": "-?(0|[0-9]\\d*)(\\.\\d+)?"
},
{
"enum": ["Infinity", "-Infinity", "NaN"]
}
]
},
"Integer": {
"type": "string",
"oneOf": [
{
"pattern": "-?(0|[0-9]\\d*)"
},
{
"enum": ["Infinity", "-Infinity", "NaN"]
}
]
},
"Boolean": {
"type": "boolean"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from airbyte_cdk.sources import AbstractSource
from airbyte_cdk.sources.streams import Stream
from airbyte_cdk.sources.streams.http import HttpStream
from airbyte_cdk.sources.utils.transform import TransformConfig, TypeTransformer

from . import pokemon_list

Expand Down Expand Up @@ -50,6 +51,8 @@ class Pokemon(PokeapiStream):
# Set this as a noop.
primary_key = None

transformer: TypeTransformer = TypeTransformer(TransformConfig.DefaultSchemaNormalization)

def path(self, **kwargs) -> str:
pokemon_name = self.pokemon_name
return f"pokemon/{pokemon_name}"
Expand Down