Skip to content

Add component.example#515

Merged
lafrech merged 1 commit intomarshmallow-code:devfrom
codeasashu:component-example
Nov 4, 2019
Merged

Add component.example#515
lafrech merged 1 commit intomarshmallow-code:devfrom
codeasashu:component-example

Conversation

@codeasashu
Copy link
Copy Markdown
Contributor

Added tests
Completes a #245 Todo

Copy link
Copy Markdown
Member

@lafrech lafrech left a comment

Choose a reason for hiding this comment

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

Thanks for this complete PR.

Just a few nitpicks and it's good to go.

I've been wondering if it would make sense to add example_helper to plugins. I guess a user could pass a schema and we could grab the example metadata from each field to build the complete example. Currently, when a user passes example as field metaclass, the value appears in the spec close to the field but not in a global response. Let's not complicate things. If someone ever needs to parse schemas to build examples, it can be done in another PR.

Comment thread tests/utils.py Outdated
Comment thread tests/test_core.py Outdated
Comment thread src/apispec/core.py Outdated
Comment thread src/apispec/core.py Outdated
"""Add a new example to the spec

:param str name: identifier by which example may be referenced.
:param dict component: schema definition.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Uh-oh, looks like we let this slip through.

Should be "example fields".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So, it should be "Add example fields to the spec", right?

Copy link
Copy Markdown
Contributor Author

@codeasashu codeasashu Nov 4, 2019

Choose a reason for hiding this comment

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

or maybe: "Add an example which can be referenced", just like we have it in parameter's docstring?

Also, I forgot to mention, :param dict component: schema definition is actually wrong, and it should be :param dict component: example object since examples are not actually definitions of anything but contains raw data?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah. Consistency first.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've added the changes. Thanks for the reviews

Comment thread tests/test_core.py Outdated
Comment thread src/apispec/core.py Outdated
Added tests
Completes a marshmallow-code#245 Todo
@lafrech lafrech changed the title Added example support Add Components.example Nov 4, 2019
@lafrech lafrech merged commit b7c2cc5 into marshmallow-code:dev Nov 4, 2019
@lafrech lafrech changed the title Add Components.example Added component.example Nov 4, 2019
@lafrech lafrech changed the title Added component.example Add component.example Nov 4, 2019
@codeasashu codeasashu deleted the component-example branch November 4, 2019 16:29
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.

2 participants