Skip to content

Commit

Permalink
markups: Fix markups
Browse files Browse the repository at this point in the history
  • Loading branch information
dhedey committed Jan 25, 2024
1 parent 75428c7 commit 3e2f06f
Show file tree
Hide file tree
Showing 33 changed files with 167 additions and 157 deletions.
14 changes: 7 additions & 7 deletions core-rust/core-api-server/core-api-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7153,7 +7153,6 @@ components:
type: object
required:
- network
- filter
properties:
network:
$ref: "#/components/schemas/NetworkIdentifier"
Expand All @@ -7167,12 +7166,13 @@ components:
StreamProofsFilterType:
type: string
enum:
- All
- Any
- NewEpochs
- ProtocolUpdateTriggers
- ProtocolUpdateInitializations
- ProtocolUpdateExecution
StreamProofsFilter:
type: object
description: If not provided, defaults to "Any".
required:
- type
properties:
Expand All @@ -7182,11 +7182,11 @@ components:
propertyName: type
mapping:
# NOTE: These need to match StreamProofsFilterType
All: '#/components/schemas/StreamProofsFilterAll'
Any: '#/components/schemas/StreamProofsFilterAny'
NewEpochs: '#/components/schemas/StreamProofsFilterNewEpochs'
ProtocolUpdateInitializations: '#/components/schemas/StreamProofsFilterProtocolUpdateInitializations'
ProtocolUpdateExecution: '#/components/schemas/StreamProofsFilterProtocolUpdateExecution'
StreamProofsFilterAll:
StreamProofsFilterAny:
allOf:
- $ref: "#/components/schemas/StreamProofsFilter"
- type: object
Expand Down Expand Up @@ -7228,7 +7228,7 @@ components:
protocol_version:
type: string
description: |
The protocol version name to filter to. This can be returned from looking at the protocol updates.
The protocol version name to filter to.
from_state_version:
$ref: "#/components/schemas/StateVersion"
description:
Expand Down Expand Up @@ -7366,7 +7366,7 @@ components:
format: int32
minimum: 0
maximum: 10000
description: An integer between `0` and `10000`, giving the total count of proofs in the returned response
description: An integer between `0` and `10000`, giving the total count of transactions in the returned response
max_ledger_state_version:
$ref: "#/components/schemas/StateVersion"
description: The maximum state version currently committed on this node's ledger.
Expand Down
33 changes: 21 additions & 12 deletions core-rust/core-api-server/src/core_api/conversions/pagination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,34 @@ pub struct SizeRange {
pub max: usize,
}

// Extracts a valid page size as per the API consistency guidelines.
pub fn extract_valid_size(
provided: Option<i32>,
size_range: SizeRange,
) -> Result<usize, ExtractionError> {
let SizeRange { min, default, max } = size_range;
match provided {
let valid_size = match provided {
Some(provided) => {
if provided < 0 {
None
return Err(ExtractionError::InvalidSize { min, max });
}
let provided = provided as usize;
if provided < min || provided > max {
return Err(ExtractionError::InvalidSize { min, max });
} else {
let provided = provided as usize;
if provided < min || provided > max {
None
} else {
Some(provided)
}
provided
}
}
None => Some(default),
}
.ok_or(ExtractionError::InvalidSize { min, max })
None => default,
};
Ok(valid_size)
}

/// Extracts a valid optional continuation token as per the API consistency guidelines.
///
/// Whilst normally such methods would not take/return an option, this is an active choice
/// to encourage/simplify following of the API guidelines, where a `continuation_token` is always
/// optional.
pub fn extract_continuation_token<T: ScryptoDecode>(
continuation_token: Option<String>,
) -> Result<Option<T>, ExtractionError> {
Expand All @@ -42,6 +47,7 @@ pub fn extract_continuation_token<T: ScryptoDecode>(
Ok(Some(id))
}

/// Maps a valid optional continuation token as per the API consistency guidelines.
pub fn to_api_continuation_token<T: ScryptoEncode>(
id_of_start_of_next_page: Option<&T>,
) -> Option<String> {
Expand All @@ -55,7 +61,10 @@ pub fn optional_max<T: Ord>(value: T, option: Option<T>) -> T {
}
}

/// Returns a page and a continuation token, representing the id of the item at the start of the next page
/// Returns a page and a continuation token from an iterator.
///
/// This follows the API consistency guidelines, although NOTE that it encodes the continuation token
/// as the id of the item at the *start of the next page*.
pub fn to_api_page<Item, ItemModel, ContinuationToken: ScryptoEncode>(
iter: &mut dyn Iterator<Item = Item>,
page_size: usize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,10 +1006,10 @@ pub mod stream_proofs_error_response_all_of;
pub use self::stream_proofs_error_response_all_of::StreamProofsErrorResponseAllOf;
pub mod stream_proofs_filter;
pub use self::stream_proofs_filter::StreamProofsFilter;
pub mod stream_proofs_filter_all;
pub use self::stream_proofs_filter_all::StreamProofsFilterAll;
pub mod stream_proofs_filter_all_all_of;
pub use self::stream_proofs_filter_all_all_of::StreamProofsFilterAllAllOf;
pub mod stream_proofs_filter_any;
pub use self::stream_proofs_filter_any::StreamProofsFilterAny;
pub mod stream_proofs_filter_any_all_of;
pub use self::stream_proofs_filter_any_all_of::StreamProofsFilterAnyAllOf;
pub mod stream_proofs_filter_new_epochs;
pub use self::stream_proofs_filter_new_epochs::StreamProofsFilterNewEpochs;
pub mod stream_proofs_filter_new_epochs_all_of;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
* Generated by: https://openapi-generator.tech
*/

/// StreamProofsFilter : If not provided, defaults to \"Any\".

#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)]
#[serde(tag = "type")]
pub enum StreamProofsFilter {
#[serde(rename="All")]
StreamProofsFilterAll {
#[serde(rename="Any")]
StreamProofsFilterAny {
#[serde(rename = "from_state_version", skip_serializing_if = "Option::is_none")]
from_state_version: Option<i64>,
},
Expand All @@ -26,7 +27,7 @@ pub enum StreamProofsFilter {
},
#[serde(rename="ProtocolUpdateExecution")]
StreamProofsFilterProtocolUpdateExecution {
/// The protocol version name to filter to. This can be returned from looking at the protocol updates.
/// The protocol version name to filter to.
#[serde(rename = "protocol_version", skip_serializing_if = "Option::is_none")]
protocol_version: Option<String>,
#[serde(rename = "from_state_version", skip_serializing_if = "Option::is_none")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@


#[derive(Clone, Debug, PartialEq, Default, serde::Serialize, serde::Deserialize)]
pub struct StreamProofsFilterAll {
pub struct StreamProofsFilterAny {
#[serde(rename = "type")]
pub _type: crate::core_api::generated::models::StreamProofsFilterType,
#[serde(rename = "from_state_version", skip_serializing_if = "Option::is_none")]
pub from_state_version: Option<i64>,
}

impl StreamProofsFilterAll {
pub fn new(_type: crate::core_api::generated::models::StreamProofsFilterType) -> StreamProofsFilterAll {
StreamProofsFilterAll {
impl StreamProofsFilterAny {
pub fn new(_type: crate::core_api::generated::models::StreamProofsFilterType) -> StreamProofsFilterAny {
StreamProofsFilterAny {
_type,
from_state_version: None,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@


#[derive(Clone, Debug, PartialEq, Default, serde::Serialize, serde::Deserialize)]
pub struct StreamProofsFilterAllAllOf {
pub struct StreamProofsFilterAnyAllOf {
#[serde(rename = "from_state_version", skip_serializing_if = "Option::is_none")]
pub from_state_version: Option<i64>,
}

impl StreamProofsFilterAllAllOf {
pub fn new() -> StreamProofsFilterAllAllOf {
StreamProofsFilterAllAllOf {
impl StreamProofsFilterAnyAllOf {
pub fn new() -> StreamProofsFilterAnyAllOf {
StreamProofsFilterAnyAllOf {
from_state_version: None,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
pub struct StreamProofsFilterProtocolUpdateExecution {
#[serde(rename = "type")]
pub _type: crate::core_api::generated::models::StreamProofsFilterType,
/// The protocol version name to filter to. This can be returned from looking at the protocol updates.
/// The protocol version name to filter to.
#[serde(rename = "protocol_version", skip_serializing_if = "Option::is_none")]
pub protocol_version: Option<String>,
#[serde(rename = "from_state_version", skip_serializing_if = "Option::is_none")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#[derive(Clone, Debug, PartialEq, Default, serde::Serialize, serde::Deserialize)]
pub struct StreamProofsFilterProtocolUpdateExecutionAllOf {
/// The protocol version name to filter to. This can be returned from looking at the protocol updates.
/// The protocol version name to filter to.
#[serde(rename = "protocol_version", skip_serializing_if = "Option::is_none")]
pub protocol_version: Option<String>,
#[serde(rename = "from_state_version", skip_serializing_if = "Option::is_none")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
///
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, serde::Serialize, serde::Deserialize)]
pub enum StreamProofsFilterType {
#[serde(rename = "All")]
All,
#[serde(rename = "Any")]
Any,
#[serde(rename = "NewEpochs")]
NewEpochs,
#[serde(rename = "ProtocolUpdateTriggers")]
ProtocolUpdateTriggers,
#[serde(rename = "ProtocolUpdateInitializations")]
ProtocolUpdateInitializations,
#[serde(rename = "ProtocolUpdateExecution")]
ProtocolUpdateExecution,

Expand All @@ -26,17 +26,17 @@ pub enum StreamProofsFilterType {
impl ToString for StreamProofsFilterType {
fn to_string(&self) -> String {
match self {
Self::All => String::from("All"),
Self::Any => String::from("Any"),
Self::NewEpochs => String::from("NewEpochs"),
Self::ProtocolUpdateTriggers => String::from("ProtocolUpdateTriggers"),
Self::ProtocolUpdateInitializations => String::from("ProtocolUpdateInitializations"),
Self::ProtocolUpdateExecution => String::from("ProtocolUpdateExecution"),
}
}
}

impl Default for StreamProofsFilterType {
fn default() -> StreamProofsFilterType {
Self::All
Self::Any
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub struct StreamProofsRequest {
/// The logical name of the network
#[serde(rename = "network")]
pub network: String,
#[serde(rename = "filter")]
pub filter: Option<crate::core_api::generated::models::StreamProofsFilter>, // Using Option permits Default trait; Will always be Some in normal use
#[serde(rename = "filter", skip_serializing_if = "Option::is_none")]
pub filter: Option<Box<crate::core_api::generated::models::StreamProofsFilter>>,
/// If specified, the maximum number of proofs that will be returned.
#[serde(rename = "max_page_size", skip_serializing_if = "Option::is_none")]
pub max_page_size: Option<i32>,
Expand All @@ -29,10 +29,10 @@ pub struct StreamProofsRequest {

impl StreamProofsRequest {
/// A request to retrieve a sublist of proofs.
pub fn new(network: String, filter: crate::core_api::generated::models::StreamProofsFilter) -> StreamProofsRequest {
pub fn new(network: String) -> StreamProofsRequest {
StreamProofsRequest {
network,
filter: Option::Some(filter),
filter: None,
max_page_size: None,
continuation_token: None,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct StreamTransactionsResponse {
pub previous_state_identifiers: Option<Box<crate::core_api::generated::models::CommittedStateIdentifier>>,
#[serde(rename = "from_state_version")]
pub from_state_version: i64,
/// An integer between `0` and `10000`, giving the total count of proofs in the returned response
/// An integer between `0` and `10000`, giving the total count of transactions in the returned response
#[serde(rename = "count")]
pub count: i32,
#[serde(rename = "max_ledger_state_version")]
Expand Down
10 changes: 5 additions & 5 deletions core-rust/core-api-server/src/core_api/handlers/stream_proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ pub(crate) async fn handle_stream_proofs(
assert_matching_network(&request.network, &state.network)?;
let mapping_context = MappingContext::new(&state.network);

let filter = request
.filter
.ok_or_else(|| client_error("filter must be present"))?;
let filter = request.filter.unwrap_or(Box::new(StreamProofsFilterAny {
from_state_version: None,
}));

let page_size = extract_valid_size(
request.max_page_size,
Expand All @@ -34,8 +34,8 @@ pub(crate) async fn handle_stream_proofs(
let database = state.state_manager.database.read_current();

use models::StreamProofsFilter::*;
let mut proofs_iter = match filter {
StreamProofsFilterAll { from_state_version } => iterate_all_proofs(
let mut proofs_iter = match *filter {
StreamProofsFilterAny { from_state_version } => iterate_all_proofs(
&database,
continue_from_state_version,
extract_from_state_version(&database, from_state_version)?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonValue;
import com.radixdlt.api.core.generated.models.StreamProofsFilterAll;
import com.radixdlt.api.core.generated.models.StreamProofsFilterAny;
import com.radixdlt.api.core.generated.models.StreamProofsFilterNewEpochs;
import com.radixdlt.api.core.generated.models.StreamProofsFilterProtocolUpdateExecution;
import com.radixdlt.api.core.generated.models.StreamProofsFilterProtocolUpdateInitializations;
Expand All @@ -37,8 +37,9 @@

import com.radixdlt.api.core.generated.client.JSON;
/**
* StreamProofsFilter
* If not provided, defaults to \&quot;Any\&quot;.
*/
@ApiModel(description = "If not provided, defaults to \"Any\".")
@JsonPropertyOrder({
StreamProofsFilter.JSON_PROPERTY_TYPE
})
Expand All @@ -49,11 +50,11 @@
)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", visible = true)
@JsonSubTypes({
@JsonSubTypes.Type(value = StreamProofsFilterAll.class, name = "All"),
@JsonSubTypes.Type(value = StreamProofsFilterAny.class, name = "Any"),
@JsonSubTypes.Type(value = StreamProofsFilterNewEpochs.class, name = "NewEpochs"),
@JsonSubTypes.Type(value = StreamProofsFilterProtocolUpdateExecution.class, name = "ProtocolUpdateExecution"),
@JsonSubTypes.Type(value = StreamProofsFilterProtocolUpdateInitializations.class, name = "ProtocolUpdateInitializations"),
@JsonSubTypes.Type(value = StreamProofsFilterAll.class, name = "StreamProofsFilterAll"),
@JsonSubTypes.Type(value = StreamProofsFilterAny.class, name = "StreamProofsFilterAny"),
@JsonSubTypes.Type(value = StreamProofsFilterNewEpochs.class, name = "StreamProofsFilterNewEpochs"),
@JsonSubTypes.Type(value = StreamProofsFilterProtocolUpdateExecution.class, name = "StreamProofsFilterProtocolUpdateExecution"),
@JsonSubTypes.Type(value = StreamProofsFilterProtocolUpdateInitializations.class, name = "StreamProofsFilterProtocolUpdateInitializations"),
Expand Down Expand Up @@ -135,11 +136,11 @@ private String toIndentedString(Object o) {
static {
// Initialize and register the discriminator mappings.
Map<String, Class<?>> mappings = new HashMap<String, Class<?>>();
mappings.put("All", StreamProofsFilterAll.class);
mappings.put("Any", StreamProofsFilterAny.class);
mappings.put("NewEpochs", StreamProofsFilterNewEpochs.class);
mappings.put("ProtocolUpdateExecution", StreamProofsFilterProtocolUpdateExecution.class);
mappings.put("ProtocolUpdateInitializations", StreamProofsFilterProtocolUpdateInitializations.class);
mappings.put("StreamProofsFilterAll", StreamProofsFilterAll.class);
mappings.put("StreamProofsFilterAny", StreamProofsFilterAny.class);
mappings.put("StreamProofsFilterNewEpochs", StreamProofsFilterNewEpochs.class);
mappings.put("StreamProofsFilterProtocolUpdateExecution", StreamProofsFilterProtocolUpdateExecution.class);
mappings.put("StreamProofsFilterProtocolUpdateInitializations", StreamProofsFilterProtocolUpdateInitializations.class);
Expand Down
Loading

0 comments on commit 3e2f06f

Please sign in to comment.