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

Openapi fix spec #30

Merged
merged 31 commits into from
Sep 16, 2024
Merged

Openapi fix spec #30

merged 31 commits into from
Sep 16, 2024

Conversation

TobiPeterG
Copy link
Contributor

This switches to openapi-codegenerator and tries to patch the spec file with the patcher from netbox. Doesn't solve all issues yet.

@TobiPeterG TobiPeterG requested a review from chadell as a code owner August 26, 2024 13:42
@TobiPeterG
Copy link
Contributor Author

The code now successfully compiles. Please check if the changes to the spec file are appropriate.

Comment on lines +15 to +19
if 'failover_strategy' in schema.get('properties', {}):
prop = schema['properties']['failover_strategy']
if 'default' in prop and prop['default'] is None:
print(f"Removing 'default: null' in {name}.failover_strategy")
del prop['default']

Choose a reason for hiding this comment

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

For reference:

        failover_strategy:
          type: object
          properties:
            value:
              type: string
              enum:
              - ''
              - active-active
              - active-passive
            label:
              type: string
              enum:
              - (unspecified)
              - Active/Active
              - Active/Passive
          default: null

Looks like the default should probably be the empty string, not null.

Choose a reason for hiding this comment

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

Also:

        failover_strategy:
          default: null
          oneOf:
          - $ref: '#/components/schemas/FailoverStrategyEnum'
          - $ref: '#/components/schemas/BlankEnum'

Not immediately clear to me whether the issue is with both or either of these cases.

Choose a reason for hiding this comment

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

Per slack it's the latter case that's an issue. Probably both are wrong though.

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Not clear yet where the null is coming from here as both the model and the serializer define blank=True and allow_blank=True but not null=True or allow_null=True here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this is an issue of the specification, right?
Should I create an issue on nautobot's project?

Choose a reason for hiding this comment

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

I think that would be appropriate, yes. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created an issue :)
nautobot/nautobot#6157

Comment on lines 23 to 34
# Replace nested `type` field in PowerFeed
if 'type' in schema['properties']:
type_property = schema['properties']['type']
if 'properties' in type_property and 'value' in type_property['properties']:
value_property = type_property['properties']['value']
if 'enum' in value_property and set(value_property['enum']) == {'primary', 'redundant'}:
print(f"Replacing complex 'type' field in PowerFeed")
schema['properties']['type'] = {
'type': 'string',
'enum': ['primary', 'redundant'],
'default': 'primary'
}

Choose a reason for hiding this comment

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

For reference:

        type:
          type: object
          properties:
            value:
              type: string
              enum:
              - primary
              - redundant
            label:
              type: string
              enum:
              - Primary
              - Redundant
          default:
            value: primary
            label: Primary

Choose a reason for hiding this comment

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

This is an intended asymmetry in the API - on responses from the server, type should be a dict with keys value and label, but on requests to the server, the client should just specify a string corresponding to the value. The PowerFeed type should only be used on the response side, on the request side see WritablePowerFeedRequest, PatchedWritablePowerFeedRequest, BulkWritablePowerFeedRequest, PatchedBulkWritablePowerFeedRequest

Same comment on the other enum fields below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this something we need to change here then and/or something that needs to be changed in the specification?
How should go-nautobot handle this?

Choose a reason for hiding this comment

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

Not sure yet. I currently believe that the generated schema is correct but there may be some nuance I'm missing.

Comment on lines 36 to 47
# Replace nested `supply` field in PowerFeed
if 'supply' in schema['properties']:
supply_property = schema['properties']['supply']
if 'properties' in supply_property and 'value' in supply_property['properties']:
value_property = supply_property['properties']['value']
if 'enum' in value_property and set(value_property['enum']) == {'ac', 'dc'}:
print(f"Replacing complex 'supply' field in PowerFeed")
schema['properties']['supply'] = {
'type': 'string',
'enum': ['ac', 'dc'],
'default': 'ac'
}

Choose a reason for hiding this comment

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

For reference:

        supply:
          type: object
          properties:
            value:
              type: string
              enum:
              - ac
              - dc
            label:
              type: string
              enum:
              - AC
              - DC
          default:
            value: ac
            label: AC

Comment on lines 50 to 60
if 'phase' in schema['properties']:
phase_property = schema['properties']['phase']
if 'properties' in phase_property and 'value' in phase_property['properties']:
value_property = phase_property['properties']['value']
if 'enum' in value_property and set(value_property['enum']) == {'single-phase', 'three-phase'}:
print(f"Replacing complex 'phase' field in PowerFeed")
schema['properties']['phase'] = {
'type': 'string',
'enum': ['single-phase', 'three-phase'],
'default': 'single-phase'
}

Choose a reason for hiding this comment

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

For reference:

        phase:
          type: object
          properties:
            value:
              type: string
              enum:
              - single-phase
              - three-phase
            label:
              type: string
              enum:
              - Single phase
              - Three-phase
          default:
            value: single-phase
            label: Single phase

Comment on lines 64 to 73
# Replace complex `type` object with a simpler string enum in Prefix
if 'type' in schema['properties']:
type_property = schema['properties']['type']
if 'properties' in type_property and 'value' in type_property['properties']:
print(f"Replacing complex 'type' field in Prefix")
schema['properties']['type'] = {
'type': 'string',
'enum': ['container', 'network', 'pool'],
'default': 'network'
}

Choose a reason for hiding this comment

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

For reference:

        type:
          type: object
          properties:
            value:
              type: string
              enum:
              - container
              - network
              - pool
            label:
              type: string
              enum:
              - Container
              - Network
              - Pool
          default:
            value: network
            label: Network

development/scripts/fix-spec.py Outdated Show resolved Hide resolved
development/scripts/fix-spec.py Outdated Show resolved Hide resolved
.travis.yml Outdated Show resolved Hide resolved
@TobiPeterG
Copy link
Contributor Author

@chadell Is there something else that should be changed? :)

README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved

- [Network Automation with Go Book](https://github.com/PacktPublishing/Network-Automation-with-Go/blob/main/ch06/nautobot/main.go)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that having an example is great to get started, and adding the reference to this book it's good too even though is using an old version

Copy link
Contributor Author

@TobiPeterG TobiPeterG Sep 14, 2024

Choose a reason for hiding this comment

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

I changed the reference to the terraform provider, as that will use the new go-nautobot code :)
Is that alright?

README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
@TobiPeterG TobiPeterG force-pushed the openapi-fix-spec branch 2 times, most recently from da86890 to 3da61de Compare September 15, 2024 09:42
.README.md Outdated

func main() {
token := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
check(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

err is not defined at this point, please remove

.README.md Outdated
check(err)

config := nb.NewConfiguration()
config.Servers[0].URL = "localhost"
Copy link
Contributor

Choose a reason for hiding this comment

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

demo.nautobot.com ?

Copy link
Contributor

@chadell chadell left a comment

Choose a reason for hiding this comment

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

LGTM

@chadell chadell merged commit 117bd94 into nautobot:main Sep 16, 2024
1 check passed
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