Progress on docs

This commit is contained in:
2024-11-10 17:45:13 -05:00
parent 2b7a97c67b
commit 3bc60af3a8
25 changed files with 246 additions and 191 deletions

View File

@@ -50,8 +50,8 @@ class IDHANApi : public drogon::HttpController< IDHANApi >
METHOD_LIST_BEGIN
ADD_METHOD_VIA_REGEX( IDHANApi::api, "/api.yaml" );
ADD_METHOD_TO( IDHANApi::apiDocs, "/api" );
ADD_METHOD_TO( IDHANApi::api, "/api" );
ADD_METHOD_VIA_REGEX( IDHANApi::apiDocs, "/api.*.yaml" );
ADD_METHOD_TO( IDHANApi::version, "/version" );

View File

@@ -10,17 +10,35 @@
namespace idhan::api
{
void IDHANApi::api( const drogon::HttpRequestPtr& request, ResponseFunction&& callback )
void IDHANApi::apiDocs( const drogon::HttpRequestPtr& request, ResponseFunction&& callback )
{
std::string path { request->getPath() };
log::info( path );
callback( drogon::HttpResponse::newFileResponse( "./pages/api.yaml" ) );
callback( drogon::HttpResponse::newFileResponse( "./pages" + path ) );
}
void IDHANApi::apiDocs( const drogon::HttpRequestPtr& request, ResponseFunction&& callback )
void IDHANApi::api( const drogon::HttpRequestPtr& request, ResponseFunction&& callback )
{
callback( drogon::HttpResponse::newRedirectionResponse( "./apidocs.html" ) );
if ( auto ifs = std::ifstream( "./pages/apidocs.html", std::ios::ate ); ifs )
{
std::size_t size { ifs.tellg() };
ifs.seekg( 0, std::ios::beg );
std::string str {};
str.resize( size );
ifs.read( str.data(), str.size() );
// create http response
auto response { drogon::HttpResponse::newHttpResponse() };
response->setContentTypeCode( drogon::ContentType::CT_TEXT_HTML );
response->setBody( str );
callback( response );
}
callback( drogon::HttpResponse::newHttpResponse() );
}
} // namespace idhan::api

View File

@@ -15,13 +15,22 @@ void IDHANApi::version( const drogon::HttpRequestPtr& request, ResponseFunction&
log::debug( "/version" );
Json::Value json;
json[ "idhan_version" ] = IDHAN_VERSION;
json[ "idhan_api_version" ] = IDHAN_API_VERSION;
json[ "idhan_server_version" ][ "string" ] =
std::format( "{}.{}.{}", IDHAN_SERVER_MAJOR, IDHAN_SERVER_MINOR, IDHAN_SERVER_PATCH );
json[ "idhan_server_version" ][ "major" ] = IDHAN_SERVER_MAJOR;
json[ "idhan_server_version" ][ "minor" ] = IDHAN_SERVER_MINOR;
json[ "idhan_server_version" ][ "patch" ] = IDHAN_SERVER_PATCH;
json[ "idhan_api_version" ][ "string" ] =
std::format( "{}.{}.{}", IDHAN_API_MAJOR, IDHAN_API_MINOR, IDHAN_API_PATCH );
json[ "idhan_api_version" ][ "major" ] = IDHAN_API_MAJOR;
json[ "idhan_api_version" ][ "minor" ] = IDHAN_API_MINOR;
json[ "idhan_api_version" ][ "patch" ] = IDHAN_API_PATCH;
json[ "hydrus_api_version" ] = HYDRUS_MIMICED_API_VERSION;
callback( drogon::HttpResponse::newHttpJsonResponse( json ) );
}
} // namespace idhan::api

View File

@@ -31,7 +31,7 @@ void HydrusAPI::apiVersion( [[maybe_unused]] const drogon::HttpRequestPtr& reque
// I'm unsure if anything would actually ever need this.
// But i figured i'd supply it anyways
json[ "idhan_server_version" ] = IDHAN_VERSION;
json[ "is_idhan_instance" ] = true;
json[ "idhan_api_version" ] = IDHAN_API_VERSION;
const auto response { drogon::HttpResponse::newHttpJsonResponse( json ) };

View File

@@ -11,7 +11,7 @@
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui-bundle.js" crossorigin></script>
<script>
url = `${window.location.protocol}//${window.location.hostname}` + (window.location.port ? `:${window.location.port}` : '') + '/api.yaml';
url = `${window.location.protocol}//${window.location.hostname}` + (window.location.port ? `:${window.location.port}` : '') + '/api/index.yaml';
window.onload = () => {
window.ui = SwaggerUIBundle({

View File

@@ -6,6 +6,14 @@
#define MAKE_IDHAN_VERSION( major, minor, patch ) int( ( major << 16 ) | ( minor < 8 ) || patch )
#define IDHAN_VERSION MAKE_IDHAN_VERSION( 0, 1, 0 )
#define IDHAN_SERVER_MAJOR 0
#define IDHAN_SERVER_MINOR 1
#define IDHAN_SERVER_PATCH 0
#define IDHAN_API_VERSION MAKE_IDHAN_VERSION( 0, 1, 0 )
#define IDHAN_API_MAJOR 0
#define IDHAN_API_MINOR 1
#define IDHAN_API_PATCH 0
#define IDHAN_SERVER_VERSION MAKE_IDHAN_VERSION( IDHAN_SERVER_MAJOR, IDHAN_SERVER_MINOR, IDHAN_SERVER_PATCH )
#define IDHAN_API_VERSION MAKE_IDHAN_VERSION( IDHAN_API_MAJOR, IDHAN_API_MINOR, IDHAN_API_PATCH )

View File

@@ -3,8 +3,8 @@
if (BUILD_IDHAN_DOCS)
find_package(Doxygen)
set(API_YAML ${CMAKE_CURRENT_SOURCE_DIR}/api.yaml)
set(API_YAML_OUT ${CMAKE_BINARY_DIR}/bin/pages/api.yaml)
set(API_YAML ${CMAKE_CURRENT_SOURCE_DIR}/api)
set(API_YAML_OUT ${CMAKE_BINARY_DIR}/bin/pages/api)
set(DOXYGEN_OUT ${CMAKE_CURRENT_SOURCE_DIR}/out)
add_custom_target(IDHANDocs DEPENDS ${API_YAML_OUT} ${DOXYGEN_OUT})
@@ -16,10 +16,14 @@ if (BUILD_IDHAN_DOCS)
COMMENT "Building doxygen docs"
)
file(GLOB_RECURSE YAML_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/api/*.yaml"
)
add_custom_command(
OUTPUT ${API_YAML_OUT}
DEPENDS ${API_YAML}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${API_YAML} ${API_YAML_OUT}
DEPENDS ${YAML_FILES}
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${API_YAML} ${API_YAML_OUT}
COMMENT "Copying API docs"
)

View File

@@ -1,173 +0,0 @@
openapi: 3.0.0
servers:
- url: /
info:
description: Standard API for IDHAN
version: "1.0.555"
title: IDHAN API
contact:
email: kj16609@lolicon.zip
tags:
- name: public
description: Public access
- name: access-locked
description: Locked behind usage of an access key
- name: tags
description: Tag related operations
- name: files
description: File related operations
components:
schemas:
TagIDSet:
description: "Two tag component ids"
type: object
properties:
namespace_id:
type: integer
subtag_id:
type: integer
TagSet:
description: "Two strings that make up a tag"
type: object
properties:
namespace:
type: string
example: "character"
subtag:
type: string
example: "toujou koneko"
TagInput:
oneOf:
- $ref: "#/components/schemas/TagIDSet"
- $ref: "#/components/schemas/TagSet"
TagColor:
description: "RBG Values are provided for ease of use."
type: object
properties:
hex:
type: string
example: "F0F0F0"
r:
type: integer
minimum: 0
maximum: 255
g:
type: integer
minimum: 0
maximum: 255
b:
type: integer
minimum: 0
maximum: 255
TagID:
type: integer
TagInfo:
type: object
properties:
tag_id:
$ref: "#/components/schemas/TagID"
color:
$ref: "#/components/schemas/TagColor"
Version:
type: object
properties:
string:
description: "Simple string for easy display"
type: string
example: "1.0.0"
major:
type: integer
example: 1
minor:
type: integer
example: 0
patch:
type: integer
example: 0
VersionInfo:
type: object
properties:
idhan_version:
$ref: "#/components/schemas/Version"
idhan_api_version:
$ref: "#/components/schemas/Version"
hydrus_api_version:
type: integer
securitySchemes:
AccessKey:
type: apiKey
in: header
name: "IDHAN-Api-Key"
responses:
AuthError:
description: API key is missing or invalid
parameters:
AccessKey:
in: header
name:
$ref: "#/components/securitySchemes/AccessKey/name"
required: true
schema:
type: string
paths:
/version:
get:
tags:
- public
summary: Returns version info
responses:
"200":
description: Json object with info
content:
application/json:
schema:
$ref: "#/components/schemas/VersionInfo"
/tag/{tag_id}/info:
get:
tags:
- tags
summary: Returns info related to the tag
parameters:
- in: path
name: tag_id
schema:
$ref: "#/components/schemas/TagID"
required: true
description: Numeric ID representing a tag
- $ref: "#/components/parameters/AccessKey"
security:
- AccessKey: [ ]
responses:
"200":
description: json
content:
application/json:
schema:
$ref: "#/components/schemas/TagInfo"
"403":
$ref: "#/components/responses/AuthError"
/tag/create:
post:
tags:
- tags
summary: Creates a tag and returns it's ID
requestBody:
description: "Must either contain a json object of namespace_id, subtag_id or namespace, subtag (See Schema)"
content:
application/json:
schema:
$ref: "#/components/schemas/TagInput"
responses:
"403":
$ref: "#/components/responses/AuthError"

53
docs/api/index.yaml Normal file
View File

@@ -0,0 +1,53 @@
openapi: 3.0.0
servers:
- url: /
info:
description: Standard API for IDHAN
version: "1.0.0"
title: IDHAN API
contact:
email: kj16609@lolicon.zip
tags:
- name: public
description: Public access
- name: access-locked
description: Locked behind usage of an access key
- name: tags
description: Tag related operations
- name: files
description: File related operations
security:
- KeyAuth: [ ]
paths:
/version:
$ref: './paths/version.yaml'
/tag/create:
$ref: './paths/tags/create.yaml'
/tag/{tag_id}/info:
$ref: './paths/tags/info.yaml'
/file/{file_id}/add_tag:
/file/{file_id}/tags:
/file/{file_id}/info:
components:
schemas:
TagInfo:
$ref: './schemas/TagInfo.yaml'
Version:
$ref: './schemas/Version.yaml'
VersionInfo:
$ref: './schemas/VersionInfo.yaml'
TagColor:
$ref: './schemas/TagColor.yaml'
TagSet:
$ref: './schemas/TagSet.yaml'
TagInput:
$ref: './schemas/TagInput.yaml'
securitySchemes:
KeyAuth:
$ref: './securitySchemes/KeyAuth.yaml'

View File

@@ -0,0 +1,19 @@
post:
tags:
- tags
- access-locked
summary: Creates a new tag, Or returns an ID of an existing one
requestBody:
description: Json object with a namespace id or text, and a subtag id, or text
required: true
content:
application/json:
schema:
$ref: '../../schemas/TagSet.yaml'
responses:
"200":
description: "Json object with tag info"
content:
application/json:
schema:
$ref: '../../schemas/TagInfo.yaml'

View File

@@ -0,0 +1,19 @@
get:
tags:
- tags
- access-locked
summary: Returns information about a tag.
parameters:
- in: path
name: tag_id
required: true
schema:
$ref: '../../schemas/TagID.yaml'
responses:
"200":
description: "Json object with tag info"
content:
application/json:
schema:
$ref: '../../schemas/TagInfoExtended.yaml'

View File

@@ -0,0 +1,12 @@
get:
tags:
- public
summary: Returns version info
security: [ ]
responses:
"200":
description: Json object with info
content:
application/json:
schema:
$ref: '../schemas/VersionInfo.yaml'

View File

@@ -0,0 +1,18 @@
description: "RBG Values are provided for ease of use."
type: object
properties:
hex:
type: string
example: "F0F0F0"
r:
type: integer
minimum: 0
maximum: 255
g:
type: integer
minimum: 0
maximum: 255
b:
type: integer
minimum: 0
maximum: 255

View File

@@ -0,0 +1,3 @@
oneOf:
- $ref: 'TagID.yaml'
- $ref: 'TagString.yaml'

View File

@@ -0,0 +1,3 @@
type: integer
minimum: 0
description: A numeric value representing a tag component

View File

@@ -0,0 +1,10 @@
type: object
properties:
tag_id:
type: integer
namespace:
$ref: './TagNamespace.yaml'
subtag:
$ref: './TagSubtag.yaml'
color:
$ref: './TagColor.yaml'

View File

@@ -0,0 +1,8 @@
type: object
allOf:
- $ref: 'TagInfo.yaml'
- type: object
properties:
items_count:
type: integer
description: "Number of items with this tag"

View File

@@ -0,0 +1,3 @@
oneOf:
- $ref: 'TagID.yaml'
- $ref: 'TagString.yaml'

View File

@@ -0,0 +1,3 @@
type: string
description: The first text component of a tag
example: 'character'

View File

@@ -0,0 +1,7 @@
description: "Two strings that make up a tag"
type: object
properties:
namespace:
$ref: 'TagComponent.yaml'
subtag:
$ref: 'TagComponent.yaml'

View File

@@ -0,0 +1 @@
type: string

View File

@@ -0,0 +1,4 @@
type: string
description: The second text component of a tag
example: 'toujou koneko'
minLength: 0

View File

@@ -0,0 +1,15 @@
type: object
properties:
string:
description: "Simple string for easy display"
type: string
example: "1.0.0"
major:
type: integer
example: 1
minor:
type: integer
example: 0
patch:
type: integer
example: 0

View File

@@ -0,0 +1,8 @@
type: object
properties:
idhan_server_version:
$ref: './Version.yaml'
idhan_api_version:
$ref: './Version.yaml'
hydrus_api_version:
type: integer

View File

@@ -0,0 +1,3 @@
type: apiKey
in: header
name: IDHAN-Api-Key