Skip to content

Add OData import support - #1649

Merged
jschoedl merged 10 commits into
datacontract:mainfrom
jahlen:feature/odata-import
Sep 25, 2026
Merged

jschoedl merged 10 commits into
datacontract:mainfrom
jahlen:feature/odata-import

Conversation

@jahlen

@jahlen jahlen commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Adds OData 4.x import from CSDL XML or JSON, using URLs or local files. Supports selecting individual EntitySets or importing all advertised EntitySets, with authentication through the existing configuration system.

Sample usage

datacontract import odata \
  --service-root-url 'https://xmart-api-public-uat.who.int/refmart/' \
  --entity-set ref_country \
  --output datacontract.yaml

Sample generated datacontract

servers:
- server: source
  type: api
  customProperties:
  - property: apiType
    value: odata
  - property: odataVersion
    value: '4.0'
  - property: odataMetadataUrl
    value: https://xmart-api-public-uat.who.int/refmart/$metadata
  - property: format
    value: json
  location: https://xmart-api-public-uat.who.int/refmart/
schema:
- name: REF_COUNTRY
  physicalType: object
  customProperties:
  - property: odataEntitySet
    value: REF_COUNTRY
  - property: odataEntitySetUrl
    value: https://xmart-api-public-uat.who.int/refmart/REF_COUNTRY
  logicalType: object
  physicalName: REF_COUNTRY
  properties:
  - name: GEO_M49_CODE
    physicalType: Edm.String
    logicalType: string
    required: false
  - name: CODE_ISO_2
    physicalType: Edm.String
    logicalType: string
    required: false
    # More properties...

I would suggest to add "odata" as a separate server type in the ODCS so that it can be handled without custom properties. Meanwhile, I have used the server type "api".

Current limitations

  • This feature implements import only.

  • Complex types, collection-valued fields, entity or container inheritance, enum types, type definitions and
    types outside the table produce errors when used by selected schemas.

  • Tests pass (uv run pytest)

  • Code formatted (uv run ruff check --fix && uv run ruff format)

  • Docs updated (if relevant)

  • CHANGELOG.md entry added

@jschoedl

Copy link
Copy Markdown
Collaborator

Hi, thank you for the PR!

The docs and tests are pretty long, can you trim them down to what is realistically needed? You can take a look at how the other importers are documented and tested for reference. (In particular, descriptions of the development process like "odataEntitySet now belongs to each schema object" should not be part of the docs - what does "now" refer to?)

@jahlen

jahlen commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

Hi Jakob,

I've updated the docs and tests now. Let me know what you think!

@jschoedl jschoedl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice!

Comment thread datacontract/imports/odata_importer.py Resolved
Comment thread datacontract/imports/odata_importer.py Resolved
Comment thread datacontract/command_import.py Resolved
Comment thread datacontract/command_import.py Resolved
Comment thread datacontract/imports/odata_importer.py Resolved

@jochenchrist jochenchrist left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM (appart from jakobs remarks)

@jahlen

jahlen commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

Hi! I've updated the code and resolved the remarks. If you think anything needs more updating just let me know.

For the unmapped OData types (Edm.Binary, Edm.Duration, etc) I don't see any good matching logical type in ODCS. I was considering vector for Edm.Binary, but as I understand it vector is fixed length. Now I changed so it will warn about unmapped types, not stop.

I'd suggest extending ODCS with a servertype for OData (so we can get better support for it and skip custom properties), and also adding a few more logical types (to cover things such as variable length binary). I don't know the process how to suggest such changes of ODCS, but I'd happily write a proposal.

@jschoedl jschoedl left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you, looks good!
To propose extensions of ODCS, you can create an issue in its repository.

@jschoedl
jschoedl merged commit b5ada1e into datacontract:main Sep 25, 2026
19 checks passed
@jahlen
jahlen deleted the feature/odata-import branch September 25, 2026 14:54
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.

3 participants