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

feat: case schemas #95

Merged
merged 2 commits into from
Sep 27, 2021
Merged

feat: case schemas #95

merged 2 commits into from
Sep 27, 2021

Conversation

marcosschroh
Copy link
Owner

@marcosschroh marcosschroh commented Apr 9, 2021

Available cases:

CAMELCASE = "camelcase"
CAPITALCASE = "capitalcase"
CONSTCASE = "constcase"
LOWERCASE = "lowercase"
PASCALCASE = "pascalcase"
PATHCASE = "PATHCASE"
SNAKECASE = "snakecase"
SPINALCASE = "spinalcase"
TRIMCASE = "trimcase"
UPPERCASE = "uppercase"
ALPHANUMCASE = "alphanumcase"

Usage:

import dataclasses
import typing
from dataclasses_avroschema import AvroModel, types, case

class UserAdvance(AvroModel):
        name: str
        age: int
        pets: typing.List[str]
        accounts: typing.Dict[str, int]
        has_car: bool = False
        favorite_colors: types.Enum = types.Enum(["BLUE", "YELLOW", "GREEN"])
        country: str = "Argentina"
        address: str = None
        md5: types.Fixed = types.Fixed(16)

        class Meta:
            schema_doc = False

UserAdvance.avro_schema(case_type=case.PASCALCASE)

>>> '{"type": "record", "name": "UserAdvance", "fields": [{"name": "Name", "type": "string"}, {"name": "Age", "type": "long"}, {"name": "Pets", "type": {"type": "array", "items": "string", "name": "Pet"}}, {"name": "Accounts", "type": {"type": "map", "values": "long", "name": "Account"}}, {"name": "HasCar", "type": "boolean", "default": false}, {"name": "FavoriteColors", "type": {"type": "enum", "name": "FavoriteColor", "symbols": ["BLUE", "YELLOW", "GREEN"]}}, {"name": "Country", "type": "string", "default": "Argentina"}, {"name": "Address", "type": ["null", "string"], "default": null}, {"name": "Md5", "type": {"type": "fixed", "name": "Md5", "size": 16}}]}'

# Normal schema
UserAdvance.avro_schema()

>>> '{"type": "record", "name": "UserAdvance", "fields": [{"name": "name", "type": "string"}, {"name": "age", "type": "long"}, {"name": "pets", "type": {"type": "array", "items": "string", "name": "pet"}}, {"name": "accounts", "type": {"type": "map", "values": "long", "name": "account"}}, {"name": "has_car", "type": "boolean", "default": false}, {"name": "favorite_colors", "type": {"type": "enum", "name": "favorite_color", "symbols": ["BLUE", "YELLOW", "GREEN"]}}, {"name": "country", "type": "string", "default": "Argentina"}, {"name": "address", "type": ["null", "string"], "default": null}, {"name": "md5", "type": {"type": "fixed", "name": "md5", "size": 16}}]}'

@codecov
Copy link

codecov bot commented Sep 24, 2021

Codecov Report

Merging #95 (c1c97fc) into master (f9861a2) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #95      +/-   ##
==========================================
+ Coverage   99.60%   99.61%   +0.01%     
==========================================
  Files           8        9       +1     
  Lines         750      788      +38     
  Branches      115      121       +6     
==========================================
+ Hits          747      785      +38     
  Misses          2        2              
  Partials        1        1              
Impacted Files Coverage Δ
dataclasses_avroschema/case.py 100.00% <100.00%> (ø)
dataclasses_avroschema/schema_generator.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f9861a2...c1c97fc. Read the comment docs.

@marcosschroh marcosschroh merged commit 00841d5 into master Sep 27, 2021
@marcosschroh marcosschroh deleted the feature/case-schemas branch September 27, 2021 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant