1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
pub mod artifacts;
pub mod coordinates;
pub mod creatures;
pub mod dance_forms;
pub mod df_st_info;
pub mod entities;
pub mod entity_populations;
pub mod historical_eras;
pub mod historical_event_collections;
pub mod historical_events;
pub mod historical_figures;
pub mod identities;
pub mod landmasses;
pub mod links;
pub mod map_images;
pub mod mountain_peaks;
pub mod musical_forms;
pub mod poetic_forms;
pub mod regions;
pub mod rivers;
pub mod site_map_images;
pub mod sites;
pub mod underground_regions;
pub mod world_constructions;
pub mod world_info;
pub mod written_content;

use okapi::openapi3::OpenApi;
use rocket::Route;
use rocket_okapi_codegen::routes_and_spec_with_openapi;

// The following variables are used by `rocket_okapi_codegen` to create the openAPI info
static APPLICATION_NAME: &str = "DF Storyteller";
static APPLICATION_DESCRIPTION: &str = "DF Storyteller is an application for parsing and \
storing Dwarf Fortress Legends files. It provides an interface for other apps to visualize the data.";
static APPLICATION_LICENSE: &str = "GPL-3.0-or-later";
static APPLICATION_LICENSE_URL: &str =
    "https://gitlab.com/df_storyteller/df-storyteller/-/blob/master/LICENSE";
static APPLICATION_DOCS_NAME: &str = "Rust Docs";
static APPLICATION_DOCS_URL: &str = "https://docs.dfstoryteller.com/rust-docs/";

fn get_spec_and_routes() -> (OpenApi, Vec<Route>) {
    let (spec, routes) = routes_and_spec_with_openapi![
        // ----------- BASIC INFO ------------------
        // DF Storyteller info
        df_st_info::get_df_st_info,
        // World Info
        world_info::get_world_info,
        world_info::list_worlds_info,
        world_info::get_world_info_count,
        // ----------- WORLD DATA ------------------
        // Artifact
        artifacts::get_artifact,
        artifacts::list_artifacts,
        artifacts::get_artifact_count,
        // Coordinates
        coordinates::get_coordinate,
        coordinates::list_coordinates,
        coordinates::get_coordinate_count,
        // Creature
        creatures::get_creature,
        creatures::list_creatures,
        creatures::get_creature_count,
        // DanceForm
        dance_forms::get_dance_form,
        dance_forms::list_dance_forms,
        dance_forms::get_dance_form_count,
        // Entity
        entities::get_entity,
        entities::list_entities,
        entities::get_entity_count,
        // EntityPopulation
        entity_populations::get_entity_population,
        entity_populations::list_entity_populations,
        entity_populations::get_entity_population_count,
        // HistoricalEra
        historical_eras::get_historical_era,
        historical_eras::list_historical_eras,
        historical_eras::get_historical_era_count,
        // HistoricalEvent
        historical_events::get_historical_event,
        historical_events::list_historical_events,
        historical_events::get_historical_event_count,
        // HistoricalEventCollection
        historical_event_collections::get_historical_event_collection,
        historical_event_collections::list_historical_event_collections,
        historical_event_collections::get_historical_event_collection_count,
        // HistoricalFigure
        historical_figures::get_historical_figure,
        historical_figures::list_historical_figures,
        historical_figures::get_historical_figure_count,
        // Identity
        identities::get_identity,
        identities::list_identities,
        identities::get_identity_count,
        // Landmass
        landmasses::get_landmass,
        landmasses::list_landmasses,
        landmasses::get_landmass_count,
        // MountainPeak
        mountain_peaks::get_mountain_peak,
        mountain_peaks::list_mountain_peaks,
        mountain_peaks::get_mountain_peak_count,
        // MusicalForm
        musical_forms::get_musical_form,
        musical_forms::list_musical_forms,
        musical_forms::get_musical_form_count,
        // PoeticForm
        poetic_forms::get_poetic_form,
        poetic_forms::list_poetic_forms,
        poetic_forms::get_poetic_form_count,
        // Regions
        regions::get_region,
        regions::list_regions,
        regions::get_region_count,
        // Rivers
        rivers::get_river,
        rivers::list_rivers,
        rivers::get_river_count,
        // Sites
        sites::get_site,
        sites::list_sites,
        sites::get_site_count,
        // Sites/Structures
        sites::get_site_structure,
        sites::list_site_structures,
        sites::get_site_structure_count,
        // Sites/SiteProperty
        sites::get_site_property,
        sites::list_site_properties,
        sites::get_site_property_count,
        // Structures
        sites::list_structures,
        sites::get_structure_count,
        // SiteProperty
        sites::list_all_site_properties,
        sites::get_all_site_property_count,
        // UndergroundRegions
        underground_regions::get_underground_region,
        underground_regions::list_underground_regions,
        underground_regions::get_underground_region_count,
        // WorldConstruction
        world_constructions::get_world_construction,
        world_constructions::list_world_constructions,
        world_constructions::get_world_construction_count,
        // WrittenContent
        written_content::get_written_content,
        written_content::list_written_contents,
        written_content::get_written_content_count,
        // ----------- IMAGES ------------------
        // MapImage
        map_images::get_map_image,
        map_images::list_map_images,
        map_images::get_map_image_count,
        map_images::get_map_image_png,
        // SiteMapImage
        site_map_images::get_site_map_image,
        site_map_images::list_site_map_images,
        site_map_images::get_site_map_image_count,
        site_map_images::get_site_map_image_png,
        // ----------- LINKS ------------------
        // Link
        links::list_link_he_hf,
        links::list_he_from_hf,
    ];
    (spec, routes)
}

/// Return a List of Routes created by Rocket
pub fn get_routes() -> Vec<Route> {
    get_spec_and_routes().1
}

/// Return a OpenApi object that can be turned into json
pub fn get_openapi_spec() -> OpenApi {
    get_spec_and_routes().0
}