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

Update datamodel-code-generator to version 0.17.0 #156

Closed
glenrobson opened this issue Jan 13, 2023 · 12 comments · Fixed by #158 or #164
Closed

Update datamodel-code-generator to version 0.17.0 #156

glenrobson opened this issue Jan 13, 2023 · 12 comments · Fixed by #158 or #164
Labels
upstream Issues caused by problems with upstream libraries

Comments

@glenrobson
Copy link
Contributor

glenrobson commented Jan 13, 2023

A couple of the issues we reported have now been fixed so we should see if we can remove the workarounds with generating the schema.

This one is to do with the lang string issues: (and we could close #23) (datamodel v 0.15.0)

koxudaxi/datamodel-code-generator#696

This one is to do with the @id and @type issues we've seen in services (datamodel v 0.14.1):

koxudaxi/datamodel-code-generator#917

we originally discussed this issue here.

@glenrobson glenrobson added upstream Issues caused by problems with upstream libraries discuss For discussion in next catchup meeting labels Jan 13, 2023
@glenrobson glenrobson changed the title Update datamodel-code-generator Update datamodel-code-generator to version 0.15.0 Jan 13, 2023
@glenrobson
Copy link
Contributor Author

Looks like koxudaxi/datamodel-code-generator#917 doesn't fix our issues as it adds a prefix before the underscore e.g. field_id we want to remove the _ from the beginning.

@glenrobson glenrobson removed the discuss For discussion in next catchup meeting label Jan 13, 2023
@koxudaxi
Copy link

@glenrobson
OK. I will think about how to resolve the problem.

@koxudaxi
Copy link

@glenrobson
I have released the new version as 0.16.1
Could you please --remove-special-field-name-prefix as CLI option?
Thank you very much!!

@glenrobson
Copy link
Contributor Author

Thanks @koxudaxi we will run a test!

@digitaldogsbody
Copy link
Member

That looks like it has fixed the issue with the _id and _type fields :)

@digitaldogsbody
Copy link
Member

The other bug with LngString seems to persist, sadly

@koxudaxi
Copy link

@digitaldogsbody Thank you for testing it.

The other bug with LngString seems to persist, sadly

Could you please explain the problem?

@digitaldogsbody
Copy link
Member

@koxudaxi Thanks so much for the responsive fixes - it makes a big difference to our project ☺️

The other issue is the one that @giacomomarchioro opened here: koxudaxi/datamodel-code-generator#696

In the types section of our schema, we have:

"lngString": {
            "title": "Language string, must have a language and value must be an array.",
            "type": "object",
            "patternProperties": {
                "^[a-zA-Z-][a-zA-Z-]*$": {
                    "type": "array",
                    "items": { "type": "string"}
                },
                "^none$": {
                    "type": "array",
                    "items": { "type": "string"}
                }
            },
            "additionalProperties": false
        },

datamodel-code-generator (0.16.1) is creating:

class LngString(Base):
    pass

    class Config:
        extra = Extra.forbid

We are expecting something like:

class LngString(Base):
    __root__: Dict[str, List[str]]

    class Config:
        extra = Extra.forbid

@digitaldogsbody
Copy link
Member

The whole schema file is here: https://github.com/IIIF/presentation-validator/blob/2f9f7e4ec5f671ebcdf8b2eef76cae2a7d50f26b/schema/iiif_3_0.json

And the command we are using is: datamodel-codegen --input iiif_3_0.json --input-file-type jsonschema --use-default --remove-special-field-name-prefix --strict-nullable --base-class .base.Base --output skeleton.py

@koxudaxi
Copy link

@digitaldogsbody
Thank you for explaining the detail
I tried the command with the master branch version.
The problem is solved with the latest code.
I will release a new version within a few days.

$ pip install git+https://github.com/koxudaxi/datamodel-code-generator.git
# generated by datamodel-codegen:
#   filename:  iiif_3_0.json
#   timestamp: 2023-01-28T09:41:10+00:00

from __future__ import annotations

from datetime import datetime
from typing import Any, Dict, List, Optional, Union

from pydantic import AnyUrl, Extra, Field, PositiveFloat, PositiveInt, constr
...

class LngString(Base):
    __root__: Union[
        Dict[constr(regex=r'^[a-zA-Z-][a-zA-Z-]*$'), List[str]],
        Dict[constr(regex=r'^none$'), List[str]],
    ] = Field(
        ..., title='Language string, must have a language and value must be an array.'
    )

...

@digitaldogsbody
Copy link
Member

Amazing, thank you so much!

@digitaldogsbody digitaldogsbody changed the title Update datamodel-code-generator to version 0.15.0 Update datamodel-code-generator to version 0.17.0 Feb 3, 2023
@digitaldogsbody
Copy link
Member

datamodel-code-generator 0.17.0 is out (https://github.com/koxudaxi/datamodel-code-generator/releases/tag/0.17.0) which contains the above fix - so we should update to that and test that it's resolved the LngString issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream Issues caused by problems with upstream libraries
Projects
None yet
3 participants