Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions nmdc_runtime/minter/domain/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from typing import Optional

from base32_lib import base32
from pydantic import BaseModel, PositiveInt
from pydantic import BaseModel, Field, PositiveInt

from nmdc_runtime.minter.config import schema_classes, typecodes
from nmdc_runtime.minter.config import typecodes


class Entity(BaseModel):
Expand Down Expand Up @@ -54,9 +54,38 @@ class MintingRequest(ValueObject):
how_many: PositiveInt


class SchemaClass(Entity):
"""An NMDC schema class for which persistent identifiers can be minted."""

# TODO: Consider renaming `id` to `class_uri` (or using a Pydantic alias to support the latter).
id: str = Field(
...,
title="Schema class URI",
description=(
"The `class_uri` of the [NMDC schema class](https://microbiomedata.github.io/nmdc-schema/#classes) "
"for which you want to mint IDs (e.g. `nmdc:Biosample`)."
),
examples=["nmdc:Biosample"],
)


class AuthenticatedMintingRequest(ValueObject):
schema_class: Entity = Entity(id=schema_classes()[0]["id"])
how_many: PositiveInt = 1
"""Parameters for requesting that one or more persistent identifiers be minted."""

# Note: In the Git commit following #cb3f128a, we started requiring that the request specify
# the `schema_class` _explicitly_, rather than falling back to _whatever_ schema class
# happened to be first in the list returned by the `schema_classes` function.
schema_class: SchemaClass = Field(
...,
title="Schema class",
description="An object identifying the NMDC schema class for which you want to mint IDs.",
)
how_many: PositiveInt = Field(
default=1,
title="How many",
description="The number of IDs you want to mint. Must be a positive integer (at least 1).",
examples=[1],
)


class ResolutionRequest(ValueObject):
Expand Down
10 changes: 10 additions & 0 deletions tests/e2e/test_minter_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,13 @@ def test_mint_id_rejects_invalid_quantity(api_site_client):
with pytest.raises(requests.HTTPError) as exc_info:
_ = api_site_client.request("POST", "/pids/mint", body)
assert exc_info.value.response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT


def test_mint_id_rejects_missing_schema_class(api_site_client):
"""Confirm a site client cannot mint an ID without specifying a schema class."""

body = {"how_many": 1}

with pytest.raises(requests.HTTPError) as exc_info:
_ = api_site_client.request("POST", "/pids/mint", body)
assert exc_info.value.response.status_code == status.HTTP_422_UNPROCESSABLE_CONTENT